-->
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.  [ 5 posts ] 
Author Message
 Post subject: Hibernate failed to create column using name 'order'
PostPosted: Sun Feb 21, 2010 10:16 am 
Newbie

Joined: Sun Feb 21, 2010 10:07 am
Posts: 3
Location: Quebec, CA
Hi,

I'm not what we can call an expert with hibernate, so before reporting this problem as I bug, I want to confirm with other the problem I have with it.

I'm using hibernate with annotation connecting to HSQLDB. I notice hibernate failed to create some tables due to wrong construction of SQL. Here the error logs :

Code:
21-Feb-2010 9:00:05 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
SEVERE: Unsuccessful: create table Inscription (id bigint generated by default as identity (start with 1), order integer not null, position integer, competitionDiscipline_id bigint not null, mount_id bigint not null, rider_id bigint not null, primary key (id))
21-Feb-2010 9:00:05 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
SEVERE: Unexpected token: ORDER in statement [create table Inscription (id bigint generated by default as identity (start with 1), order]


The error message make a lot of sense since there is the 'ORDER' keywork used as a field name, but it is possible to create a column of name 'ORDER' by using double quote.

Code:
create table Inscription (id bigint generated by default as identity (start with 1), "order" integer not null, position integer, competitionDiscipline_id bigint not null, mount_id bigint not null, rider_id bigint not null, primary key (id))


Thanks

Patrik Dufresne


Top
 Profile  
 
 Post subject: Re: Hibernate failed to create column using name 'order'
PostPosted: Sun Feb 21, 2010 10:28 am 
Beginner
Beginner

Joined: Wed Nov 21, 2007 8:02 am
Posts: 48
when we use xml mapping,

we can do the following to avoid your issue. I don't know if it works in annotation.

<property name="order" column="`order`"/>


Top
 Profile  
 
 Post subject: Re: Hibernate failed to create column using name 'order'
PostPosted: Tue Feb 23, 2010 4:00 pm 
Beginner
Beginner

Joined: Tue Aug 25, 2009 11:42 am
Posts: 49
Guys order is an SQL keyword. let me know which database allows a column to be named such. And even if 'order' works, I would recommend not using that.
By the way, with Hypersonic, u can't have a column named POSITION either.


Top
 Profile  
 
 Post subject: Re: Hibernate failed to create column using name 'order'
PostPosted: Thu Mar 04, 2010 5:45 pm 
Newbie

Joined: Sun Feb 21, 2010 10:07 am
Posts: 3
Location: Quebec, CA
I understand that order is a reserved name. same as position, date, select, and so on, but it's should prevent hibernate nor the user to create such column. There is `` in SQL so hibernate should used them.


Top
 Profile  
 
 Post subject: Re: Hibernate failed to create column using name 'order'
PostPosted: Fri Mar 05, 2010 3:27 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
kavithakaran has answered this already. You need to put backticks around the column name. With annotations you do like this: @Column(name="`order`")


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.