JBoss Community

ID auto generation for MySQL on JBoss AS 7

created by koshey in JBoss AS 7 Development - View the full discussion

Hi everyone,

I need help to resolve such problem. Application needs to support several DB (MySQL, Oracle). After migration to JBoss 7 entity id auto generation was broken.

Etity example:

 

 

@Entity

@Table(name="foo")

public class Foo {

 

 

          private Integer id;

          private String model;

 

          @Id

          @SequenceGenerator(name="foo_seq_gen", sequenceName="foo_0", initialValue=1, allocationSize=1)

          @Column(name="id", updatable=false)

          @GeneratedValue(generator = "foo_seq_gen")

          public Integer getId() {

                    return id;

          }

          public void setId(Integer id) {

                    this.id = id;

          }

 

          @Column(name="model", length=64, updatable=false)

          public String getModel() {

                    return model;

          }

          public void setModel(String model) {

                    this.model = model;

          }

}

 

 

For Oracle all still works fine. But when trying to perform create operation on MySQL an error occures:

 

 

15:34:56,290 ERROR [org.hibernate.util.JDBCExceptionReporter] (http-localhost-127.0.0.1-8080-1) Table 'scheme.foo_0' doesn't exist

 

 

Thus MySQL tries to access unexistent table as sequence insteed use native autogeneration mechanism.

 

 

Does anybody know the cure?

 

 

Environment:

MySQL 5.5.16

JBoss AS 7.1.0.Beta1

Hibernate 3.6.1

Reply to this message by going to Community

Start a new discussion in JBoss AS 7 Development at Community