- 
        1. Re: How to use @Id @GeneratedValue(strategy=GenerationType.Ahstang Mar 1, 2007 1:19 PM (in response to tonylmai)"tonylmai" wrote: 
 Can I create a new object of this class with just the message and let Hibernate create the id?
 Yes"tonylmai" wrote: 
 In the database end, do I create the table for this entity with column id declared as bigint?
 Hibernate does this automatically for you if you set "hibernate.hbm2ddl.auto" property to "create"
- 
        2. Re: How to use @Id @GeneratedValue(strategy=GenerationType.Atrickyvail Mar 1, 2007 1:26 PM (in response to tonylmai)In Enterprise JavaBeans 3.0 (O'Reilly 2006) it states "The AUTO strategy tells the persistence provider that you are allowing it to generate the key for you" (page 94). 
 I don't specifically know the Hibernate implements this feature, but might I suggest that you utilize the features of your database to create primary keys instead.
 With Postgresql you could use a mapping like this:@Id @Column(name = "id", unique = true, nullable = false) @SequenceGenerator(name="identifier", sequenceName="ppl_id_seq", allocationSize=1) @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="identifier") @NotNull public int getId() { return this.id; }
 In this manner Hibernate would assign primary keys from the Postgresql sequence rather than internally. This would allow Hibernate to "play nicely" with other database users.
- 
        3. Re: How to use @Id @GeneratedValue(strategy=GenerationType.Atonylmai Mar 1, 2007 3:20 PM (in response to tonylmai)It turned out that the @Id @GeneratedValue(strategy=GenerationType.AUTO) worked just fine. 
 The problem with my code was that I had a constructor that takes in the message.
 In order for the id to be generated by the Persistent layer, I needed to construct the object using the default constructor and then used the setter to set the message attribute.
 Thanks for the help.
 Regards,
 Tony
 
    