This content has been marked as final.
Show 1 reply
-
1. Re: How to use @Id @GeneratedValue(strategy=GenerationType.A
rabbiaqaswar Mar 5, 2007 3:44 AM (in response to tonylmai)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!