These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: @GeneratedValue and hbm2java
PostPosted: Thu Jun 04, 2009 2:21 am 
For my Seam app, I use Hibernate Tools (hbm2java) via 'seam generate-entities' command to reverse engineer my tables.

I am using sqljdbc.jar (MSSQL 2005 RDBMS) version 1.2.

I noticed that the following line is always omitted in the entity class that is generated for a table that has an identity column as PK (i.e. auto-generated/incremented PK int):

Code:
@GeneratedValue(strategy=GenerationType.IDENTITY)


So I end up with an entity class like this:

Code:
@Entity
public class Inventory implements Serializable {

        @Id
        private long id;
...
}


Is there a way I can instruct hbm2java to include the @GenerateValue annotation in the entity class which is based on table with identity PK? If yes, how?

Currently, I must add this code manually...


Top
  
 
 Post subject: Re: @GeneratedValue and hbm2java
PostPosted: Thu Jun 04, 2009 5:19 pm 
So I found a partial answer in Bauer/King JPA/Hibernate book.

In section 2.3.2 Customizing reverse engineering, there is an example foo.reveng.xml file.

For a particular table, you can specify the Hibernate identifier generator as follows:

Code:
<table name="MESSAGES" schema="PUBLIC" class="Message">
    <primary-key>
         <generator class="increment"/>
         <key-column name="MESSAGE_ID" property="id" type="long"/>
   </primary-key>
</table>


But how can you configure this xml file such that it uses IDENTITY column for @GeneratedValue for all tables that will be reverse engineered?

There are not a lot of example on customizing the revengr. Perhaps it's best to view the revengr dtd???


Top
  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.