Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Query on various properties wrt auto table generator

 
Jack Bush
Ranch Hand
Posts: 235
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 235
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic