java - Hibernate, id, oracle, sequence -


My database is Oracle, and my id column value is an oracle sequence, this sequence is executed by a trigger, therefore, Prior to getting the ID line, each row is triggered to use this sequence. So I know that I can define ID strategy generation in my unit class.
  @GenericGenerator (name = "generator", strategy = "increment") @ id @ generatedValue (generator = "generator")   

or

  @ id @ generatedValue (strategy = GenerationType.AUTO, generator = "idGenerator") @Sequence Generator (name = "idGenerator", serial name = "ID_SEQ")   < P> or  
  @ id = generatedValue (strategy = GenerationType.AUTO)   

In fact confused, can someone shed some light on this subject ? Please explain clearly ..

I also had a project where an Oracle DB is my @ unit class As you said, one sequence generates the ID for PK through the trigger, it was one of those comments that I used in one of these classes:

  @ ID = Generated Values ​​(strategy = generation type AUTO, generator = "G1") @Sewence generator (name = " Public1.exe ();} {this.id return; G1 ", serial name =" LOG_SEQ ") @ column (name =" id ", unique = true, zero = false, exact = 22, scale = 0) }   

This is the second syntax that you have shown in your post. There is no call to the trigger in the Java code because the trigger is managed by DB. I remember that I had to sequence and trigger at the same time in DB, if I did not want problems, the trigger asks that the Id of the line is zero or = 0 to enter. The order in this case is called LOG_SEQ.

So if you give value to your unit's ID, it can be inserted into DB (if the ID does not exist) and the order will not be asked. Try to see the trigger's code, what it really is.

Comments