Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

native generator class in hibernate

I have this part of hibernate mapping xml file, and I was looking for a good example for what does native mean.

<hibernate-mapping>
 <class name="com.hib.Task" table="tasks">
  <id name="id" type="int" column="id" >
   <generator class="native"/>
  </id>

I know it's something related to unique identifier property, but I would really like to have an example.

Sorry for the newbie question, I'm new to hibernate and programming in general :) Thank you!

like image 226
Rimchik Avatar asked May 04 '13 09:05

Rimchik


People also ask

What does generator class native do in Hibernate mapping?

Native means Your generator will use identity or sequence columns according to what your current database support. selects identity, sequence or hilo depending upon the capabilities of the underlying database. lets the application assign an identifier to the object before save() is called.

What is hibernate sequence generator?

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 class is responsible to generate the queries in hibernate?

Sr.No. This property makes Hibernate generate the appropriate SQL for the chosen database. The JDBC driver class.


1 Answers

Native means Your generator will use identity or sequence columns according to what your current database support.

Docs explained about each strategy here

http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/mapping.html#mapping-declaration-id

native

selects identity, sequence or hilo depending upon the capabilities of the underlying database.

assigned

lets the application assign an identifier to the object before save() is called. This is the default strategy if no element is specified.

For example: In Mysql if you have primary key column as a auto_increment, the db will be updated using this strategy

like image 154
Suresh Atta Avatar answered Oct 13 '22 01:10

Suresh Atta