Discussion:
[jboss-user] [JBoss Tools] - Using hibernate Tools to generate Sql Script
Chetan Shinde
2013-02-13 05:22:32 UTC
Permalink
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]
Max Rydahl Andersen
2013-02-14 18:35:05 UTC
Permalink
Max Rydahl Andersen [https://community.jboss.org/people/maxandersen] created the discussion

"Re: Using hibernate Tools to generate Sql Script"

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

--------------------------------------------------------------
Hi,

as you have correctly identified its hibernate-core that is generating these scripts.

Best if you open a bug on hibernate jira ( https://hibernate.onjira.com/browse/HHH https://hibernate.onjira.com/browse/HHH) with the details, if you have a pullrequest even better.

When you open the bug please do leave a comment here with the jira url so users that bump into this can find it.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/797757#797757]

Start a new discussion in JBoss Tools at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2128]
Chetan Shinde
2013-02-15 06:08:18 UTC
Permalink
Chetan Shinde [https://community.jboss.org/people/chetansh] created the discussion

"Re: Using hibernate Tools to generate Sql Script"

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

--------------------------------------------------------------
hello Max,

I had already raised a ticket at hibernate tools . HBX-1217 https://hibernate.onjira.com/browse/HBX-1217 https://hibernate.onjira.com/browse/HBX-1217
But as you suggested to have it at Hibernate ORM I have created the same here too : https://hibernate.onjira.com/browse/HHH-8008 https://hibernate.onjira.com/browse/HHH-8008

Regards,
Chetan
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/797817#797817]

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