I am new to hibernate and I want to insert primary number in my table for unique identification. I am using Oracle as my database so do I need to create sequence in oracle to get auto increment generation number ?
I am using below code but it is not working. I have not created any sequence yet.
@Id
@Column(name = "id" )
@GeneratedValue ( strategy = GenerationType.TABLE)
I have used AUTO
, SEQUENCE
and IDENTITY
but nothing works for me.
this is one way of using Oracle sequence in a JPA mapped entity:
@Id
@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQUENCE_NAME")
@SequenceGenerator(name = "SEQUENCE_NAME", sequenceName = "SEQUENCE_NAME", allocationSize = 1, initialValue = 1)
In this way your persist() method will ask for the next value of the sequence in order to use it as ID for your entry.
You can ue this @GeneratedValue(strategy=GenerationType.AUTO)
@Id
@Column(name = "id" )
@GeneratedValue(strategy=GenerationType.AUTO)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With