JBoss Community

Using hibernate Tools to generate Sql Script

created by Chetan Shinde in JBoss Tools - View the full discussion

We wanted to generate SQL Script (DDL) from POJO class which are Hibernate Annotated. I have tried using both hibernate3 maven plugin as well as with the Schema Exporter.

 

Now this class also has a Sequecne Generator defined, and I was expecting that there would be a Sequence script generated for it as well.

 

 

This is what the code looked like in the Entity with respect to the Sequence, the allocationSize here is defined as 50, I have tried using all different sizes.

 

@Entity @SequenceGenerator(name="sessionInfoIdSeq", sequenceName="SESSIONINFO_ID_SEQ", allocationSize=50)

 

public class SessionInfo {

 

@Id  @GeneratedValue(strategy = GenerationType.AUTO, generator="sessionInfoIdSeq")
private Integer          id;

 

I am using following JARS:

 


I am using the following jars : hibernate-tools - 3.2.4.GA, hibernate-core - 3.6.1.Final, hibernate-entitymanager - 3.6.1.Final, hibernate-validator - 4.1.0.Final, hibernate-validator-legacy - 4.0.2.GA and DB related jars.

 

Now when I tried debugging the code using the SchemaExporter example I found that the class in hibernate-core jar was getting called for generating the sequence text.

 

The problem is that it was only creating create sequence SESSIONINFO_ID_SEQ;

 

At line 146 on SequenceGenerator.java it was using

String[] ddl = dialect.getCreateSequenceStrings(sequenceName) from the Dialect class which happened to be deprecated.

 

This method implementation was

 

public String[]  getCreateSequenceString(String sequenceName) {

return "create sequence " + sequenceName; //starts with 1, implicitly

 

 

The Dialect API said instead to usefollowing method.

 

 

protected String  getCreateSequenceString(String sequenceName, int initialValue, int incrementSize) throws MappingException {

                               if ( supportsPooledSequences() ) {

                                              return getCreateSequenceString( sequenceName ) + " start with " + initialValue + " increment by " + incrementSize;

                               }

                               throw new MappingException( "Dialect does not support pooled sequences" );

               }

 

I checked the latest APi of the hibernate-core and it too uses the deprecated method.

 

Any inputs on this would be appreciated.  Do I need to raise a JIRA?

 

I have attached a sample example that I used to  generate the Code, SchemaExporter.7z.

 

Regards,

Chetan

Reply to this message by going to Community

Start a new discussion in JBoss Tools at Community