6

I am trying to make a native named query.I saw the link

result-set-mapping-complex-mappings

<sql-result-set-mapping name="BookAuthorMappingXml">
   <entity-result entity-class="org.thoughts.on.java.jpa.model.Author">
    <field-result name="id" column="authorId"/>
    <field-result name="firstName" column="firstName"/>
    <field-result name="lastName" column="lastName"/>
    <field-result name="version" column="authorVersion"/>
</entity-result>

   <entity-result entity-class="org.thoughts.on.java.jpa.model.Book">
       <field-result name="id" column="id"/>
       <field-result name="title" column="title"/>
       <field-result name="author" column="author_id"/>
       <field-result name="version" column="version"/>
   </entity-result>
</sql-result-set-mapping>

the number of columns i have is more than 20.Is there is way to map all columns in one go

I am using hibernate 4.2

6
  • Are you looking for something like stackoverflow.com/a/17210746/2646526? Commented Apr 2, 2017 at 21:01
  • yes but using named queries and method like defined in question Commented Apr 3, 2017 at 4:13
  • something like this? github.com/kiegroup/jbpm/blob/master/jbpm-persistence/… Commented Apr 6, 2017 at 11:13
  • 1
    You could create a new Entity class that has all the fields you want and not bother describing each fieldresult. That way instead of an Object[] each row would give you a well-described class you won't even have to typecast. Commented Apr 7, 2017 at 10:23
  • I dont want to create a new entity class as the number of fields are too many and this will make me change the entire references Commented Apr 7, 2017 at 10:26

1 Answer 1

2
+25

What you need is an hibernate mapping auto generation. You can follow the blog from mkyong

https://www.mkyong.com/hibernate/how-to-generate-code-with-hibernate-tools/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.