0 Replies Latest reply on Jul 19, 2007 6:13 PM by asaf sh

    Toplink->Hibernate, GenerateSequence Issue

    asaf sh Expert


      I am trying to migrate an application from GF that uses Toplin as JPA to Jboss with Hibernate,

      I'm still having a confusion of how to generate IDs as generic as possible,

      Usually my app is deployed with Oracle 9/10 or Mysql DBs and I'd like to have my application be as generic as possible,

      I tried just to use '@Id @GeneratedValue' annotations but with Oracle it just didn't work. so my entities ID get method looked like:

      @Id @GeneratedValue //JB
       public Long getMyId() {
       return myId;

      So, with Toplink, I solved it by using GenerateSequences, which worked fine for Mysql too.

      It looked like:

      @SequenceGenerator(name="MYTABLE_GEN",sequenceName="MYTABLE_SEQ", allocationSize=1)
      @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="MYTABLE_GEN")
       public Long getMyId() {
       return myId;

      When I tried to deploy my application with Jboss, I got the following exception:

      Caused by: org.hibernate.MappingException: could not instantiate id generator
       at org.hibernate.id.IdentifierGeneratorFactory.create(IdentifierGeneratorFactory.java:98)
       at org.hibernate.mapping.SimpleValue.createIdentifierGenerator(SimpleValue.java:152)
       at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:192)
       at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
       at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:713)
       ... 99 more
      Caused by: org.hibernate.MappingException: Dialect does not support sequences
       at org.hibernate.dialect.Dialect.getSequenceNextValString(Dialect.java:595)
       at org.hibernate.id.SequenceGenerator.configure(SequenceGenerator.java:65)
       at org.hibernate.id.SequenceHiLoGenerator.configure(SequenceHiLoGenerator.java:43)
       at org.hibernate.id.IdentifierGeneratorFactory.create(IdentifierGeneratorFactory.java:94)
       ... 103 more

      What am I doing wrong? and most important, what's the best practice of generating regular long IDs in order to support most of the DB vendors? (especially Mysql/Oracle)