简体   繁体   中英

hibernate native query mapping

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

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM