java - Get Hibernate Entity instance from id column in SQLQuery result -


I have non-hibernate database tables that have IDs for hibernate entities ( createSQLQuery

), which gives me the ID, so that I can load the institutions again.

I want to do this in one step, and I think I can do it with the addEntity , but I'm not sure how to be right (being hibernate Documentation web site is below. Again.) I can use the addEntity when all columns of the entity table are present, but I only have the ID.

It complains about the missing columns:

  return (list & gt; menu & gt;) session.createSQLQuery (select from "from_selected unit, where Foreign_key_en =? ") .addEntity (" entity_id ", MyEntity.class) .setLong (0, foreigner) .list ();  

I think you want something like this:

  Session.createSQLQuery ("select {entity. *} To entity_table {entity} ou ....") .addEntity ("entity", Entity.class). (Bind parameter) .list ();  

Hibernate, "{entity. *}" Will expand, which will be the column related to entity_table.

However, if you have an ID already, you can only use the session. Load () them to convert them to real examples (well, lazy-load proxy).


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -