1

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

1 Answer 1

6

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;

Check this link

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.