Reputation: 6646
I have a Table (for a long time ago), call it TABLE_A, and I have an entity class for this Table:
@Entity
@Table(name = "TABLE_A")
public class TableA implements Serializable {
@Id
@Basic(optional = false)
@Column(name = "ID")
//what else should I write here, to get the value from the existing sequence (seq_table_a_id) from database?
private Long id;
@Basic(optional = false)
@Column(name = "VALID_TO_DT")
private String name;
getters/setters...
}
I had created a sequence for this table in ORACLE a long time ago, and I want to give values for the new item's ID from this sequence. How should I write this code in java entity with annotations? If you could write an example for my code, that would be helpful!
And should I write anything else maybe in the persistance.xml?
The name of the existing sequence is: seq_table_a_id
Upvotes: 1
Views: 2356
Reputation: 7163
You should check the annotation @GeneratedValue
and @SequenceGenerator
@Id
@GeneratedValue(generator="seqGen")
@SequenceGenerator(name="seqGen",sequenceName="seq_table_a_id", allocationSize=1)
private Long id;
Upvotes: 6