sequence 1 « Map « JPA Q&A

1. Customization of Hibernate sequence generation

I have one hibernate sequence, that generates all sequence-numbers in my app. When I generate the schemas from hibernate (target Oracle10), it genererates:

create sequence hibernate_sequence;
I would like to change the configuration ...

2. Hibernate JPA Sequence (non-Id)

Is it possible to use a DB sequence for some column that is not the identifier/is not part of a composite identifier? I'm using hibernate as jpa provider, and I have ...

3. How to use a Oracle function for the ID in Hibernate

Until recently we used Oracle sequences to generate the IDs of a table. This is now changed, a new ID is now calculated by an Oracle function. Which means that my ...

4. How are managed the sequences by JPA and Hibernate?

I am using Hibernate in my project, and many of my entities use a sequence for their technical keys. For example:

@Table(name = "T_MYENTITY")
@SequenceGenerator(name = "S_MYENTITY", sequenceName = "S_MYENTITY")
public class MyEntity {


5. firePropertyChange on Sequence generated Id

When calling persist the setId method never gets called which in turns causes the firePropertyChange not to execute. I need to fire the changeSupport method because I have functionality that dependants ...

6. What is a good strategy for migrating a hibernate class from a sequence based integer primary key to a GUID primary key while retaining the old keys for backward compatiblity?

We have an extensive class hierarchy (using the joined-subclass model) where the base class has a Long primary key generated from a sequence in the DB. We are working on ...

7. What is the proper JPA mapping for @Id in parent and unique sequence in base classes

I have a class hierarchy:

abstract DomainObject {
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="SEQ")
    @Column(name = "id", updatable = false, ...

8. Oracle hibernate sequence generator problem

I am developing an application using oracle 11g, Java(struts2) and Hibernate. I have table named mytemp with column mytemp_id which is of type NUMBER(22,0). In my mytemp.hbm.xml file id is as given below

<id ...

9. Hibernate save to get sequences a second time

I have a class like this (with getters and setters, all mapped to hibernate, each with a sequence to oracle DB)

 public class A{
       private ...

10. Creating a sequence based on some criterions

I have the following class

public class Foobar {
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;


11. Using Hibernate sequence generators manually

Basically, I want a way to access sequence values in a database-neutral way. The use case is that I have a field on an entity that I want to set based on ...

12. Why doesn't the JPA spec (including 2.0) or Hibernate extension allow u to specify a generator e.g. Oracle sequence for the @Version annotation

I think the preamble of my use case cluttered my actual point, so I am restating more succinctly: Why can't @Version take a generator and allow me to assign a sequence ...

13. How to create and read a sequence in Hibernate?

I need to use a sequence to get a unique value. The production code uses postgres but I would like to access it via Hibernate so that I can test this ...

14. sequence generation in hibernate?

I have one field in my table and values for that field willbe generated by the sequence which i have given in hbm mapping. now my question is, if i provide ...

15. How to use @GeneratedValue in a non pk field

I would like to know how we could use a sequence in JPA. We have a non-pk field which value must come from a sequence in DB. How could I update ...

16. Hibernate does not generate identifier when using Oracle sequence

I have the following mapping

@SequenceGenerator(name="sacpSequenceGenerator", sequenceName="SACP_SEQ")
public class Sacp {

    private Integer id;

    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="sacpSequenceGenerator")
    public Integer getId() {

17. What happens if hibernate_sequences table is accidentally reset?

I am using hibernate with ID annotations:

@Column(name = "ID", nullable = false)
@GeneratedValue(strategy = GenerationType.TABLE)
For some reason the hibernate_sequences table, which is managed by hibernate, has been reset. ie. Newly inserted entities ...

18. @GeneratedValue(strategy = GenerationType.SEQUENCE) and startVaule

when using the @GeneratedValue Annotation in Hibernate, and adding a new Entity to DB it has the id 1 ... n . Is is it possible to set the first value, ...

19. How to use existing Oracle sequence to generate id in hibernate?

I have legacy oracle db with a sequence named 'PRODUCT_ID_SEQ'. And here the mapping of Product class for which I need generate correct ids:

public class Product {
   @GeneratedValue(strategy = ...

20. "correct" way to select next sequence value in HSQLDB 2.0.0-rc8

suppose i have a sequence, called TEST_SEQ what would be the correct way of selecting its next value ? this does not work:

select next value for TEST_SEQ
probably because it expects a "FROM" clause. looking ...

21. Hibernate: can I override an identifier generator using XML with a custom generator?

I want to use a custom sequence generator in my application, but the entity is located in a domain model jar that is shared with other applications. Apparently entity annotations can ...

22. Problem with HSQLDB & SequenceGenerator

I have an entity which has an ID field:

@Column(name = "`U##ID_VOIE`")
@GeneratedValue(generator = "VOIE_SEQ")
private String id;
The class has the sequence generator defined as well:
@SequenceGenerator(name = "VOIE_SEQ", sequenceName = "VOIE_SEQ")
and the Oracle schema ...

23. Configuring hibernate.reveng.xml to detect a sequence PK generator with hibernate3-maven-plugin and Postgre

is there a way to configure hibernate3-maven-plugin so that a sequence generator is detected for a primary-key? I'm using a bottom-up approach for hibernate configuration (which means letting hibernate-tools generate the ...

24. Why is an oracle sequence named hibernate_sequence being created with JPA using Hibernate with the Oracle 10g dialect?

All my entities use this type of @Id

@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "MYENTITY_SEQ")
@SequenceGenerator(name = "MYENTITY_SEQ", sequenceName = "MYENTITY_SEQ")
@Column(name = "MYENTITY", nullable = false)
private Long id;
@Column(name = "MYENTITY")
I find that an oracle ...

25. Calling next value of a sequence in jpa

I have a class mapped as an Entity to persist it in a database. I have an id field as the primary key so every time the object is persisted the ...

26. Hibernate sequence on oracle, @GeneratedValue(strategy = GenerationType.AUTO)

I'm usign @GeneratedValue(strategy = GenerationType.AUTO) to generate and id on my entity. I don't now how it works, but on my chils table, generates id values, that follow the parent sequence.

//parent table

27. Oracle and HIbernate, db sequence generator issues

I have the following entity (getters and setters ommited)...

@Table(name = "TBL_PROJECT_RUN")
public class ProjectRunEntity {

    @Column(name = "ID")
    @GeneratedValue(generator = "StakeholdersSequence")

28. JPA sequence for serial number

I wonder is there a clean (or native) way to generate sequence for a table, to use it as a serial number. It needs to be consecutive (1, 2, ...

29. Hibernate with MySQL : Auto-Generate Id : Equivalent of Sequence (Oracle) in MySQL

As far as i Understand, when 'Native' class is used for auto id generation in Oracle, a single hibernate sequence is created, from where all the IDs are supplied to whichever ...

30. Mysql custom sequence generator ( like oracle)

I want to have two auto_increment column's per table, but mysql allows only one auto_increment columns. So, I tried replicating the oracle sequence using my own table. Here is the schema.

create table ...

31. Hibernate - List sequence number auto-generation without gaps and starting from zero

I have UserObject which contains a list of SearchLog objects. This search log list size is defined to be at max 5.
Now whenever I add a search log to the UserObject ...

32. Proper way to retrive sequence int after entity save with hibernate and postgresql?

... right now, this is how I'm getting the id from save(entity) method:

        Serializable save =;
    return Integer.valueOf(save.toString());
Being a complete ...

33. @SequenceGenerator on class annotated with @MappedSuperclass

I have following structure of my entities:

public abstract class BaseEntity {
  @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seqGenerator")
  private Long id;

@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@SequenceGenerator(name = "seqGenerator", sequenceName = "DICTIONARY_SEQ")
public abstract ...

34. Hibernate sequence generates non-continous values

I am using a hibernate sequencegenerator to auto-generate unique values for my primary key column.The sample code is given below.

@Table(name = "REQUEST")
@javax.persistence.SequenceGenerator(name = "REQ_SEQ", sequenceName = "REQUEST_SEQ")
public class Request {
 * ...

35. Can I create my own sequence in Hibernate?

Can I create my own sequence in Hibernate, like I have a database sequence and I have to add 2 characters before the sequence?

36. Hibernate/Oracle seqhilo generator

I'm trying to configure a seqhilo generator for a Hibernate application on Oracle.

<id name="idTest" type="int">
       <column name="ID_TEST" precision="6" scale="0" />

37. Hibernate and Postgresql - generator class in hibernate mapping file

The ids in my postgresql database are auto-incremental (there are sequences defined in a database). When creating a hibernate mapping files I set the class generator to increment:

<class name="model.Names" schema="public" table="names">

38. Hibernate, mapping of foreign keys that have been generated by a sequence in the parent table

I have a 1:n relation in the database and java objects that represent the relation with hibernate. The primary key of the parent table is generated with a database sequence, the child object ...

39. hibernate auto create in-memory hsqldb causes Sequence not found

I'm using hibernate as my jpa provider and want it to create a in-memory hsqldb on startup using: But for some reason I get exceptions like below in my logs. Things seems to ...

40. Using @GeneratedValue(strategy=GenerationType.TABLE), the sequence_next_hi_value is an int(11) but my table have a id column bigint(20)

I am using @Id with @GeneratedValue(strategy=GenerationType.TABLE), just checked that hibernate have created a table hibernate_sequences, but the column type for the sequence_next_hi_value is an int(11). I have some entities (I mean ...

41. Implementing sequence in Java using Hibernate

I am using Java and Hibernate as ORM tool. Is there any way i can implement sequence in Java using Hibernate? Currently I am using Oracle sequences to achieve this, but that ...

42. sequence does not exist exception using eclipseLink with oracle db

I've got the following JPA entity:

@Table(schema = "myschema")
@SequenceGenerator(schema = "myschema", name = "seqGenerator", 

43. Getting the Sequence Value of hibernate / Knowing the id hibernate inserted

I have two tables. One table having sequence and other table does not. i need to use the same id which got inserted to second table for business purposes. Currently im getting ...

44. Hibernate use of PostgreSQL sequence does not affect sequence table

I've configured Hibernate to use PostgreSQL sequence (via annotations) to generate values for primary key id column as follows:

@Column(name="id", unique=true, nullable=false)
public int getId() {
What I ...


What is the exact meaning of SEQUENCE_NEXT_HI_VALUE in HIBERNATE_SEQUENCES when I am using javax.persistence.GenerationType.TABLE for ID generation? Apparently, it is not the next plain ID that will be assigned to a new ...

46. How to make a Hibernate application DB-independent?

We are currently using Oracle 10g internally for our project, and that is not likely to change, but eventually we are going to offer this application to other customers and we ...

47. Pull from Oracle sequence with Hibernate

I've a sequence defined in my Oracle database. Can I pull from this sequence using Hibernate? I don't want to use the sequence for generating ids for my objects, so @GeneratedValue ...

48. JPA bigdecimal problem in hibernate

I have used maven plugin for hibernate and it has generated entity classes without identifing sequences that are related to ID fields, id fields are generated as BigDecimal... now even if ...

49. JPA @EmbeddedId is not generating sequence

I have a table which has composite primary key consisting one sequence and two foreign keys I am able to persist My entity class but it is not generating according to the ...

50. oracle stored procedure generates larger numbers through hibernate than it does alone

We have a stored procedure that generates numbers for entry ids (entry_id_seq). With the following setting, the code generates a relatively large number than it is called with SQL directly. For ...

51. Exception: Could not synchronize database state with session

I have an web application developed on spring and hibernate 3.0 and deployed on apache tomcat 6. I am getting below error when I am trying to insert the data to the ...

52. Hibernate Apache Derby Custom Sequence

I am trying to investigate the generator class in the ID sequence generation of Hibernate. I tried to use the sequence generator on a very simple mapping

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping ...

53. Specifying distinct sequence per table in Hibernate on subclasses

Is there a way to specify distinct sequences for each table in Hibernate, if the ID is defined on a mapped superclass? All entities in our application extend a superclass called DataObject ...

54. Hibernate generating two different sequence Ids for PostgreSQL insert

I have an entity defined with a sequence-generated primary key:

@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "id_key_gen")
@SequenceGenerator(name = "id_key_gen", sequenceName = "id_key_seq")
@Column(name = "id", unique = true, nullable = false)
public int getId() {

55. How do I set a hibernate sequence manually in mysql?

I'm doing some data migration after some data model refactoring and I'm taking a couple tables with composite primary keys and combining them into a larger table and giving it its ...

56. Get from oracle sequence with hibernate

I am working with hibernate, and a oracle 10 db. I need to get the next sequence value from a table, and want to know how. I saw this article, ...

57. Sequence Diagram for interaction between hibernate and database

I need to create a general sequence diagram for the the interaction of hibernate and a any database. It needs to be very generic and application to all transaction between hibernate and ...

58. Mapping PostgreSQL serial type with Hibernate annotations

I am using Hibernate 3.3 and PostgreSQL 8.x and would like to use Hibernate annotations to map an auto-incremented column which is NOT a primary key. It doesn't matter if the ...

59. Using sequence in MySQL and Hibernate

I'm working on a project that uses Hibernate and MySQL. I intend to use sequence to generate ID for all tables in database. (It's hard to describe my question, so I ...

60. Different PostgreSQL sequence ID in the database and in JPA

I am genuinely puzzled... but first, let me give you a rough overview. I've done some restructuring in a database, by merging 4 tables into two. All tables have simple numeric sequences ...

61. catch oracle sequence and set it to another field in JPA

An enity bean has generated sequence id (oracle primary key). We need to catch this sequence somehow on persist and set it to another field. For example:

class Entity {

62. How To Use Sequence In Hibernate As A Property In XML Mapping

how do I use a sequence in hibernate? In the documentation it mentions to use a

element. however, i want the sequence to be a column instead of an ID. how do I ...

63. Hibernate, Oracle, Sequence and One To Many Problem

I am having an issue with doing a one line save on a one to many object. That foreign key does not get populated in the child objects. Aren't ...

64. How to create a Java(6) Hibernate(3.6) Entity or other construct to create a unique combination of a string + int

I'm working on a desktop application in Java6 using H2 as the db and Hibernate 3.6. Because of a construct with a third-party library involving JNI and some interesting decisions made a ...

65. JPA mapping error for sequence number

I've been building a portion of an application to persist a user's dashboard objects and the JPA has been messing me up for ages. I've got an abstract Widget class that all ...

66. Hibernate, id, oracle, sequence

My database is Oracle, and my id column value is an Oracle sequence, this sequence is executed by a trigger, so, before each row is inserted this trigger use this sequence ...

67. Issue with Hibernate Inheritance. Subclass using wrong sequence

My mappings are below. Here is the base class for all classes. There is no table for this class. All subclasses user id as their PK.

public abstract class Model {

68. hibernate oracle sequence produces large gap

I am using hibernate 3 , oracle 10g. I have a table: subject. The definition is here

     SUBJECT_ID NUMBER (10), ...

69. Using primary key from a sequence on hibernate

How can a use primary key in hibernate from a Postgres sequence? I need the primary be autogenerated, and them how i can get the sequence value for use in Hibernate this is ...

70. Atomically fetch and increase sequence value in MySql

I convert the DB from Oracle to MySQL. I'm using both Java & Hibernate. When I used oracle I had the following method that gave me a brand new and unused sequence value:

protected ...

71. JPA IdGeneration strategy AUTO

I want to have an entity with AUTO IdGeneration strategy, I need it work both on Oracle and MySQL, and I need to specify sequence names for each entit in case ...

72. Get Real JPA Id Sequence Assigned (Solved)

How can I retrive the real value assigned to a entity?, I have an entity (Example.class) the important part is:

@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="S_4866_1")
@SequenceGenerator(name="S_4866_1", sequenceName="S_4866_1", allocationSize=1)
Long idArr;  
I have a method in ...

73. Why most hibernate applications are using sequence for id generation?

Why most hibernate application are using sequence for id generation? Why not use the default GenerationType=AUTO in @GeneratedValue annotation? P.S. In my professional career I see everybody is use sequences, but I don't ...

74. Hibernate "could not get next sequence value" oracle

i get this error could not get next sequence value when I try to save this Entity with Hibernate:

package beans;

import javax.persistence.*;

@Table(schema = "EVGENY")
public class Article {
    @SequenceGenerator(name="ArticleGen", sequenceName="ARTICLESEC")

75. Sequences not getting auto generated as per the SQL Sequences in JPA

I have two managed entities as Question & Answer Options. Im passing Answer Options as a list in Question Class.

@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)

76. Postgresql/openJPA (geronimo) Sequence Issue

I am having a weird problem with a sequence. Im using postgresql 9 with geronimo 2.2. I have created the sequence PLANTS_ID_SEQ inside the db environment and when I try to ...

77. Custom sequence in Hibernate that should reset yearly

I'm working on simple application that uses Spring MVC 3 and hibernate 3. I have a requirement to generate ID in the following format.

Month/Year/number(number will increase). 
Month and year values do ...

78. about jpa sequence generation

Hello every body I have used following code in my jpa project for working of sequence
generation,its giving exception that pre-allocation size is not set correctly,but
I have been set it correctly,interesting fact ...

79. Weird id values in Postgresql with JPA 2 Sequence generation

The entity has the following annotations on the id column:

@SequenceGenerator(name = "JOB_MISFIRE_ID_GENERATOR", sequenceName="job_misfire_sequence", allocationSize=10)
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "JOB_MISFIRE_ID_GENERATOR")
@Column(unique = true, nullable = false)
private Long id;
In the database, I have the following:

80. Manage Hibernate Generator Sequence

I need help related to Hibernate Generator Sequence. Is it possible to manage with Hibernate java class a sequence defined in DB (Oracle) mapped by hibernate hbm file ? I mean, update the ...

81. Hibernate: two sequences within a single entity with JPA

I have a mapping class using JPA annotations, and I want it to use two separate sequences for two fields:

@Table(name="my_table", schema="schema") 
public class MyClass

82. get next sequence value from database using hibernate

I have an entity that has a NON-ID field that must be set from a sequence. Currently, I fetch for the first value of the sequence, store it on the client's side, ...

83. How to select a list of 100 next sequence values from a database

select nextval ('mySchema.mySequence')
This command will return the next value of a sequence. How can I get the next N values from a sequence in SQL? My current setup uses postgreSQL, and Hibernate's native ...

84. HiberNate generated sequence value not in Sync with DB

I am using Oracle as backend and when i try to insert any entry the sequence which hibernate is generating is of the order of "50010255" but in my db the ...

85. org.hibernate.exception.GenericJDBCException: could not get next sequence value

I have a problem with Hibernate. When I want to save an object into database, I get this exception:

org.hibernate.exception.GenericJDBCException: could not get next sequence value
25P02, current transaction is aborted, commands ignored ...

86. Hiberate mapping and java code for a database sequence

I have a sequence in the DB like this

        INCREMENT BY 1
        START ...

87. configure id sequence hibernate generator

Can I configure Hibernate not to do the select seq.nextval from dual as separate call before the actual insert ?

org.hibernate.jdbc.AbstractBatcher about to open PreparedStatement (open PreparedStatements: 0, globally: 0) 
org.hibernate.SQL select ...

88. sequence generator for secondary tables

We have two tables (T1 & T2) that is mapped to a single class (C1) using @Table and @SecondaryTable annotations respectively. Is there a way to specify the sequence generator for ...

89. How can I sequence a column within a table using SQL (MySQL)?

I have a list mapped using Hibernate with an index column. The table looks like this:

mysql> select * from chart;
| id | report | indx | name     ...

90. Sequence Generator in persistence.xml

In JPA, generally we specify the sequence generator in the entity bean. Can we specify this in the persistence.xml? if yes, pls share the steps neeeded

91. Hibernate with Oracle sequence doesn't use it

I have configured hibernate to use oracle sequence. Sequence is created with cache=20, increment=1. All works fine, hibernate persisting entities. The id value is strange: 50,51....76,201,202...209,1008,1009,5129,5130 .... If I ask for sequence ...

92. Hibernate generator class increment vs sequence?

i can see many generator classes at for generating identifier. But if i look at increment and sequence, i am not sure whqat is difference and which one is ...

93. using oracle sequences with jpa (toplink)

I have a sequence object in my oracle db:

create sequence BASE_SEQ
minvalue 1
maxvalue 9999999999999999999999999999
start with 100
increment by 1
I use jpa(toplink) for my web application. I have base class for all my db ...

94. Hibernate issue

Hi I have a domain object lets say Student and its Roll no as a primary key here is the sample mapping for it.

@Column(name = "Roll_NO", unique = ...

95. hibernate_sequence duplicate entries for sequence_name

I use hibernate with oracle . hibernate_sequence table have duplicate entries for few sequence_name (One in lower case and another with uppercase letter)

@Table (name = "service")
public class Service implements Serializable {

96. Which is better: single global sequence vs. sequence per table?

In a JPA/Hibernate application using native Oracle sequences, is it better to use a single global sequence like hibernate_sequence, or to define a separate sequence per table? It seems like a single ...

97. Eclipse Glassfish 3.1 adapter - SEQUENCE already exists error

I have some problems with Eclipse server adapter for Glassfish 3.1. I am using the JPA auto generated identifiers. If the server is running and I have a create-and-drop policy for ...

98. Get next sequence number

I have a class Account with a property number which has as value fe:


[plan_code].[year].[sequential number]
Now I have this number property mapped as a String. So when I want to create a second ...

99. ORA-02289: sequence does not exist when upgrade Hibernate 3 to hibernate 4

I have an issue related to sequence not found when I upgrade hibernate from 3.5 to 4.0.0.RC6:

at org.hibernate.internal.SessionImpl.persist( [hibernate-core-4.0.0.CR6.jar:4.0.0.CR6]
at org.hibernate.internal.SessionImpl.persist( [hibernate-core-4.0.0.CR6.jar:4.0.0.CR6]
at org.hibernate.ejb.AbstractEntityManagerImpl.persist( [hibernate-entitymana
... 159 more
Caused by: java.sql.SQLSyntaxErrorException: ORA-02289: sequence does not ...

100. Generating identifiers for use with Hibernate's "assigned" generator

We tell Hibernate how to generate identifiers using the <generator> tag. For example:

<generator class="sequence">
    <param name="sequence">person_id_sequence</param>
I wish to use <generator class="assigned">. As per the documentation:
assigned ...