-->
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.  [ 21 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Way to control column order with Ant schemaexport task
PostPosted: Tue May 15, 2007 10:32 am 
Newbie

Joined: Tue May 15, 2007 10:12 am
Posts: 1
Is there any way to control the column order in the generated SQL using the Ant schemaexport task? The columns from each entity appear to be listed in alphabetical order and I would like them to be in the same order as they occur in the annotated entity source file.
Thanks.
--Jim

Hibernate version: Hibernate Annotations 3.2.1.GA; Hibernate Tools 3.2.0.beta9a

Name and version of the database you are using: MySQL 4.1.12

Annotated Java entities:
Code:
@MappedSuperclass
public abstract class PersistentEntity implements Serializable {

    @Id @GeneratedValue
    @Column(updatable = false, insertable = false)
    @org.hibernate.annotations.Generated(org.hibernate.annotations.GenerationTime.INSERT)
    private int dbid;
   
    @Column(updatable = false, insertable = false, columnDefinition = "timestamp default current_timestamp on update current_timestamp")
    @org.hibernate.annotations.Generated(org.hibernate.annotations.GenerationTime.ALWAYS)
    private Timestamp dbupdate;
   
    @Column(updatable = false, columnDefinition = "timestamp default 0")
    private Timestamp dbentry;
    // getters and setters
}

Code:
   
@Entity
@Table(name = "Reservation.resource")
public class ReservationResource extends PersistentEntity {
   
    @OneToMany(cascade={CascadeType.PERSIST, CascadeType.MERGE}, mappedBy = "resource")
    private Set<Reservation> reservations = new HashSet<Reservation>();
    @Column(nullable=false)
    private String code;
    private String resourceName;
    private String resourceType;
    private String program;
    private String useListName;
    private String whoListName;
    private String technologyListName;
    @Column(length=65535)
    private String description;
    // getters and setters here
}


The generated SQL (show_sql=true):
Code:
    create table Reservation.resource (
        dbid integer not null auto_increment,
        dbentry timestamp default 0,
        dbupdate timestamp default current_timestamp on update current_timestamp,
        code varchar(255) not null,
        description text,
        program varchar(255) not null,
        resourceName varchar(255),
        resourceType varchar(255),
        technologyListName varchar(255),
        useListName varchar(255),
        whoListName varchar(255),
        primary key (dbid)
    ) type=InnoDB;


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 15, 2007 2:32 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
i'm surprised they are ordered...should be added just like what is in the mapping. Must be something the AnnotationConfiguration does. Take a look in there.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Re: Way to control column order with Ant schemaexport task
PostPosted: Thu Mar 06, 2008 4:17 am 
Newbie

Joined: Mon Oct 16, 2006 10:23 am
Posts: 8
coblej wrote:
The columns from each entity appear to be listed in alphabetical order and I would like them to be in the same order as they occur in the annotated entity source file.

Hibernate Annotations 3.2.1.GA


It seems this behaviour changed between 3.2.0.GA and 3.2.1.GA: 3.2.0.GA still lists the columns in order of occurence. I wonder if there was a reason for this, nothing obviously related in the changelog afaics.

coblej wrote:
Code:
   
@Entity
@Table(name = "Reservation.resource")


Hm, I usually do

Code:
   
@Entity(name = "Reservation.resource")


as the entity names need to be unique also, and the table name defaults to the entity name.


Top
 Profile  
 
 Post subject: Re: Way to control column order with Ant schemaexport task
PostPosted: Tue May 27, 2008 12:38 pm 
Newbie

Joined: Tue May 27, 2008 12:35 pm
Posts: 8
coblej wrote:
Is there any way to control the column order in the generated SQL using the Ant schemaexport task? The columns from each entity appear to be listed in alphabetical order and I would like them to be in the same order as they occur in the annotated entity source file.
Thanks.
--Jim


Did you (or anyone else) ever resolve this? It's causing me some pain now and it looks like hibernate 3.3 still does the same thing. I hate the thought of messing with the AnnotationConfig class because I'm afraid i'll cause some unintended consequences.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 02, 2008 10:45 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
It is sorted to ensurce deterministic ordering across clusters.

We can't rely on the vm to return the methods in the same order every time so we had to do something.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 31, 2008 5:51 am 
Newbie

Joined: Thu Jul 31, 2008 5:44 am
Posts: 9
How about an attribute setting in the @Column annotation to specify the order in which the columns should appear in the table.
This setting when used can override the default behaviour.

The lack of control over the order of the columns presents a particular problem for me when using Oracle. I get the following error:

Code:
OrA-24816: Expanded non LONG bind data supplied after actual LONG or LOB column.


This is due to the fact that Oracle insists on BLOB columns being the last ones in an insert statement. Since I have no control over the order of the columns I can't inforce it.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 31, 2008 10:26 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
would be interesting to see how other JPA implementations handles that special case....in any case, this should go in jira.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 04, 2008 6:52 am 
Newbie

Joined: Thu Jul 31, 2008 5:44 am
Posts: 9
I agree. But I think this may be Hibernate can take the lead on this issue.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 05, 2008 4:12 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
well, if someone already handled this stupid oracle limitation it would save us time ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 06, 2008 1:08 pm 
Newbie

Joined: Thu Jul 31, 2008 5:44 am
Posts: 9
I agree max, it really is a silly limitation. My guess is that Oracle have pushed an implementation problem onto their users; they must have uncovered a limitation in the way they handle BLOBs in INSERT and UPDATE statements. But rather than fixing this limitation, they have chosen to push it onto the user and let the user fix it.

Oracle aside though, this could actually be a nice feature, in situations where you actually want to have control over the order in which hibernate creates your table columns. Though I agree this would be more of a convenience than a necessity.

I guess we will have to wait for Oracle to take notice. Let's hope they are monitoring this forum.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 30, 2008 9:07 am 
Beginner
Beginner

Joined: Wed Jan 31, 2007 6:54 am
Posts: 22
I also think specifying column order through annotations would be a nice feature.
In our project, due to existing databases, we are required to follow a certain convention for column ordering when creating new tables.
Using annotations to create the new tables leads to the wrong order, and we have to go back to using xml mappings to make it work.
Is there a jira ticket on this?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 02, 2008 6:13 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Here are a couple related ones:

http://opensource.atlassian.com/project ... se/ANN-673

http://opensource.atlassian.com/project ... se/HBX-629

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 28, 2009 2:23 pm 
Newbie

Joined: Sat Feb 28, 2009 2:12 pm
Posts: 1
Hi,
i've just get the same problem too.
Unfortunately I'm having problems with order of 2 column in a many to many associative table.
With an inverse order of columns i get an inverse order of primary key definition too, this lead to a less performing index cause we normally need much more to query just 1 colum of composite key... the 2nd column in alphabetical order.

I've seen that HBX-629 is closed as "Won't Fix" than... there's any workaround at this problem using annotations?

Tnx


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 25, 2009 6:09 am 
Newbie

Joined: Tue Mar 11, 2008 12:49 pm
Posts: 2
Hi,

And what users of CompositeUserType should do? Since it rely heavily on properties indexes and order?

Thank you in advance,
Michael


Top
 Profile  
 
 Post subject: Re: Way to control column order with Ant schemaexport task
PostPosted: Tue May 05, 2009 6:19 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
I dont have any good ideas on how we can ever solve this in a good way.

If you got ideas that can make annotations or tools know what order you actually want then provide a patch.

_________________
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.  [ 21 posts ]  Go to page 1, 2  Next

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.