[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - Re: How to use @Id @GeneratedValue(strategy=GenerationType.A
rabbiaqaswar
do-not-reply at jboss.com
Mon Mar 5 03:44:46 EST 2007
When you will create your entity you will only have to set the desc property. The 'id' property will be set since it has these @Id @GeneratedValue(strategy=GenerationType.AUTO) annotations.
The database end depends upon the table generation strategy in your persistence.xml file. If this is what you have in persistence.xml:
| <properties>
| <property name="hibernate.hbm2ddl.auto" value="create"/>
| </properties>
|
OR
| <properties>
| <property name="hibernate.hbm2ddl.auto" value="update"/>
| </properties>
Then you dont have to create the tables yourself, they'll be created. If you want to create the tables yourself then just like anyother column in a table you should also create the column for your id.
The @GeneratedValue annotations generates only int, Long or String values(but do check for yourself). So you should check what should be the datatype of your id. Say i have a table Customer in db with property Number CUSTOMERID. In my entity Customer, i will have property Long customerId. Then i use:
| @Id
| @GeneratedValue(strategy=GenerationType.AUTO)
It works fine.
hope this helps!
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4024993#4024993
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4024993
More information about the jboss-user
mailing list