1

Today my DB responsible boss told me that I'm using a wrong sequence, in JPA/Hibernate, but I weren't so I checked up on why my generated table entries had a higher ID than the normal(trigger) generated entries.
And I found This on SO which is horrific for me, since I use this DB sequence in DB triggers to generate entries. Which means, as far as I know. That in 50x time My DB will start to hit the sequence numbers generated by my Java application.

To avoid this, I need to use the specific sequence, and not the sequence*50. But havn't found out how to do this, can anyone help me?

Thanks in advance

currently it is defined like this:

@Id
@Column(name = "PVP_COST_ELEMENTS_ID")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "wtStatSEQ")
@SequenceGenerator(name = "wtStatSEQ", sequenceName = "warehouse.wt_stat_SEQ")

1 Answer 1

1

In hibernate you can specify the used seq explicitly by using the annotations

@Id
@Column(name = "COLUMN_NAME", nullable = false)
@GeneratedValue(strategy = AUTO, generator = "yourEntitySeqGen")
@SequenceGenerator(name = "yourEntitySeqGen", sequenceName = "SEQUENCE_NAME_IN_YOUR_DATABASE")

cheers

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

1 Comment

Updated the Q a bit. So it is because of strategy = auto/sequence ? :)

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.