These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: predictable field order from hbm2ddl for annotated classes?
PostPosted: Fri Sep 21, 2007 10:10 pm 
Newbie

Joined: Fri Sep 21, 2007 9:58 pm
Posts: 6
HibernateTools 3.2.0.beta9a

When I use hibernate-tools hbm2ddl to create ddl from hbm.xml files, fields in the resulting "create tables" DDL are in a consistent order from invocation to invocation. When I create ddl from JPA-annotated classes, the fields seem to be emitted in random order. This causes "svn diff" to report spurious differences where there are none, making it difficult to detect whenthe schema has changed.

Is there a way to cause hbm2ddl to emit fields in a predictable order?

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 26, 2007 4:23 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
This is because JPA uses the order the vm returns the properties/methods.

I seem to recall that emmanuel added or want to add something that makes this more predictable.

But making it exactly the same as what hbm.xml's would do I guess is not really possible.

I'll ping emmanuel to let him comment on this one.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: re: predictable field order from hbm2ddl for annotated class
PostPosted: Wed Sep 26, 2007 8:24 am 
Newbie

Joined: Fri Sep 21, 2007 9:58 pm
Posts: 6
Quote:
But making it exactly the same as what hbm.xml's would do I guess is not really possible.


Making it the same as hbm.xml order is not a requirement for me - but making JPA emit predictable order vs. a previous invocation of itself would be very desirable. Even just a simple lexical sort of the field names would solve my problem (comparing one DDL script with an earlier one).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 26, 2007 12:35 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
It is a lexical order starting with Hibernate Annotations 3.3.0. I had to do that because the VM does not guarantee the order when reading methods and fields from a class.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: re: predictable field order from hbm2ddl for annotated class
PostPosted: Tue Oct 16, 2007 6:10 pm 
Newbie

Joined: Fri Sep 21, 2007 9:58 pm
Posts: 6
When can we expect a version of hibernate-tools to include annotations 3.3.0? I just tested tools 3.2.0-beta11 and it still uses annotations 3.2.1.GA.

Quote:
It is a lexical order starting with Hibernate Annotations 3.3.0. I had to do that because the VM does not guarantee the order when reading methods and fields from a class.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 17, 2007 3:21 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you should be able to put in hibernate-anntations 3.3.0 into hibernate tools and it should work - if not then please let me know.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 20, 2008 7:39 pm 
Newbie

Joined: Fri Sep 21, 2007 9:58 pm
Posts: 6
I realize this thread is long dead, but I would like to ask again.

At the time Max replied, I tested the 3.3.0.GA annotations jar and did not see success. I thought perhaps it was a configuration error on my part, and since this was not a vital requirement for my project, I put it aside.

It has now become more important (the DBA at my customer is complaining about diff'ing DDL scripts :))

I've now updated to hibernate-tools 3.2.0.GA (which includes hibernate-annotations-3.3.0.GA). I still see the same unsorted behavior. For example, here's the result of regenerating the schema after making a simple name change in a different table's field (via @JoinColumn(name="new_name")):

Code:
@@ -2252,8 +2252,8 @@
         last_name varchar(255) not null,
         password varchar(255),
         username varchar(255) not null,
-        portfolio_company_id integer,
         user_type_id integer not null,
+        portfolio_company_id integer,
         primary key (user_id),
         unique (username)
     );


(the diff has hundreds of these sorts of changes -- both the original and new ddl were created with the same hibernate-tools version and the only change between each DDL is a single field name change on an unrelated table.

I don't know what else to try. Here's the hiberanate.cfg.xml I'm using when running the ant task. Is there something missing in here that would cause the annotations code to sort my properties?

Code:
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
   <property name="dialect">org.hibernate.dialect.MySQLDialect</property>

   <mapping class="com.myproject.MyClass1" />
   <mapping class="com.myproject.MyClass2" />
       ...

    </session-factory>
</hibernate-configuration>


Thanks for any advice!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 25, 2008 1:55 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you will need to take a deep dive in to the code to figure out why this is happening....or create a test case that illustrates the behavior and report it against hibernate annotations or hibernate core (or in the unlikely case it is hibernate tools doing some weird sorting)

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.