This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Query on various properties wrt auto table generator    Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Query on various properties wrt auto table generator    " Watch "Query on various properties wrt auto table generator    " New topic
Author

Query on various properties wrt auto table generator

Jack Bush
Ranch Hand

Joined: Oct 20, 2006
Posts: 235
Hi All,

Could someone clarify the following aspects in terms of table generation in Glassfish and MySQL:

( i ) What does the IDENTITY table generation type do?
( ii ) Does MySQL support the SEQUENCE generator strategy that is declared in @javax.persistence.SequenceGenerator? This is a more efficient build-in structure to generate IDs sequentially.
( iii ) Lastly, does Glassfish support auto schema generation which eliminate the needs to declare @JoinColumn or PrimaryKeyJoinColumn?

Thanks a lot,

Henry
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

javax.persistence.GenerationType.IDENTITY

The IDENTITY option simply allows the database to generate a unique primary key for your application. No sequence or table is used to maintain the primary key information, but instead, the database will just pick an appropriate, unique number for Hibernate to assign to the primary key of the entity. With MySQL, the first lowest numbered primary key available in the table in question is chosen, although this behavior may differ from database to database.


I've used @Identity and the @TableGenerator annotations withy MySQL quite successfully. Their use is documented at the end of this tutorial:

Primary Key Generation Strategies with Hibernate JPA and MySQL Database


Here's a Hibernate Exmample for the @TableGenerator annoation:

Jack Bush
Ranch Hand

Joined: Oct 20, 2006
Posts: 235
Hi Cameron,

Just want to say thank you for such a detail reply to this question. It covered everything that I was after.

You set the standard for others to follow.

Thanks,

Jack
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Query on various properties wrt auto table generator
 
Similar Threads
autogenerated keys
sequence generator with mysql
Leaving any property unmapped to a column in Hibernate using annotation
Hiberante annotations
hibernate mapping xml