I have (non-Hibernated) database tables that contain ids for Hibernate entities. I can query them (using createSQLQuery
), which gives me the ids, from which I can then load the entities.
I'd like to do that in one step, and I think I can do that with addEntity
, but I am not sure how exactly. (Hibernate's documentation web site is down. Again.) I can use addEntity
when all the columns for the entity table are present, but I have only the id now.
This complains about the missing columns:
return (List<MyEntity>) session.createSQLQuery(
"select entity_id from the_table where foreign_key_value = ?")
.addEntity("entity_id", MyEntity.class)
.setLong(0, foreignKey).list();