I am quite new to development with databases, so maybe this question is not entirely spot on, but I'd appreciate if someone can make it a bit clearer to me... I've read all about sequences, and how they are preferred over identities. I have a hypothetical question. If I were to use a sequence to generate my PK along with Hibernate (data insertion) and Liquibase (schema creation), what would be the right spot to define sequence?
For example: Sequence generation on class level.
User.java
@Entity
@Table(name = "USER")
public class User {
@Id
@SequenceGenerator(name = "USER_SEQ", sequenceName = "USER_SEQ")
@GeneratedValue(strategy = SEQUENCE, generator = "USER_SEQ")
@Column(name = "ID")
private Long id;
// other fields
}
Or other example: Sequence generation on Schema level.
changelog.xml
<changeSet author="wesleyy">
<createSequence catalogName="cat"
cycle="true"
incrementBy="1"
maxValue="1000"
minValue="10"
ordered="true"
schemaName="public"
sequenceName="user_seq"
startValue="1"/>
</changeSet>
Is it required to define a sequence in both Liquibase and Hibernate? What exactly is the difference between the two?