[jboss-user] [JBoss Tools] - Using hibernate Tools to generate Sql Script

Chetan Shinde do-not-reply at jboss.com
Wed Feb 13 00:22:32 EST 2013


Chetan Shinde [https://community.jboss.org/people/chetansh] created the discussion

"Using hibernate Tools to generate Sql Script"

To view the discussion, visit: https://community.jboss.org/message/797369#797369

--------------------------------------------------------------
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
[https://community.jboss.org/message/797369#797369]

Start a new discussion in JBoss Tools at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2128]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20130213/6e02b8e7/attachment.html 


More information about the jboss-user mailing list