Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate ID Generator

Anyone know of some good tutorials on how to create a custom ID generator for hibernate?

like image 502
mainstringargs Avatar asked Jan 30 '09 13:01

mainstringargs


People also ask

What is ID generator in Hibernate?

A generator class is used to generate an ID for an object, which is going to be inserted in the database as a primary key. The ID is a unique identifier for the objects of the persistent class. We can use any generator classes in our application as per our requirements.

Does Hibernate need ID?

Yes, hibernate requires an Id. Sometimes if you are dealing with a legacy database that for whatever reason does not have a key, you can define the key in Hibernate to be a composite key of all the columns for example, as this will be guaranteed to be unique.

What is sequence generator in Hibernate?

SEQUENCE is the generation type recommended by the Hibernate documentation. The generated values are unique per sequence. If we don't specify a sequence name, Hibernate will reuse the same hibernate_sequence for different types.

What is Hibernate ID New_generator_mappings?

id. new_generator_mappings that directs how identity or sequence columns are generated when using @GeneratedValue . In JBoss EAP 6, the default value for this property is set as follows: When you deploy a native Hibernate application, the default value is false .


2 Answers

A cursory search of Google for 'hibernate custom id generator tutorial' turned up the following possibilities. I've excluded those that don't look useful and summarized the content of each.

  • http://www.devx.com/Java/Article/30396 - covers the issues of generating an ID before the data is persisted (and hence does not yet have a business key).
  • http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html_single/#mapping-declaration - the whole document is very useful but not so much a tutorial as reference. Ideal when looking at the other tutorials.
  • http://www.javaworld.com/javaworld/jw-08-2008/jw-08-hibernate-annotations.html shows how to use annotations to set up your schema (including auto-generated values).

Hope that helps.

like image 55
paxdiablo Avatar answered Oct 19 '22 11:10

paxdiablo


http://resource.visual-paradigm.com/vpsuite2.3sp1/custom_id_generator.html

Though this link demonstrates Visual-Paradigm tool for generating Custom ID generator, but the idea of Hibernate Custom ID generator can be learnt from the same

like image 34
Rutesh Makhijani Avatar answered Oct 19 '22 09:10

Rutesh Makhijani