-->
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: Issue with column named ORDER
PostPosted: Tue Mar 09, 2010 10:54 pm 
Newbie

Joined: Tue Mar 09, 2010 10:45 pm
Posts: 3
I've recently upgraded to Hibernate 3.5.0-CR-1.

Several of my tables have columns named "order".
It worked before, but now the SQL statement that Hibernate generates is malformed around the word "order", namely it's missing the tablename infront of the column name, as in this example (plus there's an extra empty line):

select
footerlink0_.id as id30_,
footerlink0_.locationId as locationId30_,
footerlink0_.locationLevel as location3_30_,

order as order30_,
footerlink0_.text as text30_,
footerlink0_.type as type30_,
footerlink0_.url as url30_ from
footerLinks footerlink0_
where
footerlink0_.locationLevel=?
and footerlink0_.locationId=?
and footerlink0_.type=?;

The db dialect is MySQL, and the server is (understandably) unhappy with the statement.
I do agree that "order" is not the best name for a database column, but still...

When it was working, Hibernate was generating this statement instead:

select
footerlink0_.id as id30_,
footerlink0_.locationId as locationId30_,
footerlink0_.locationLevel as location3_30_,
footerlink0_.order as order30_,
footerlink0_.text as text30_,
footerlink0_.type as type30_,
footerlink0_.url as url30_
from
footerLinks footerlink0_
where
footerlink0_.locationLevel=?
and footerlink0_.locationId=?
and footerlink0_.type=?

So, any suggestions?
Thanks,
Radu


Top
 Profile  
 
 Post subject: Re: Issue with column named ORDER
PostPosted: Wed Mar 10, 2010 6:34 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Quote:
I do agree that "order" is not the best name for a database column, but still...


"order" is a reserved keyword on most databases (except MySQL) therefore I would say that your were lucky that it worked until
now (Hiberante3.3).
In order to fit standard naming conventions I suggest you to change name for those attributes if you intend to use Hiberante3.5.
Otherwise you have to open an issue on hibernate jira (in hope that someone will fix this).


Top
 Profile  
 
 Post subject: Re: Issue with column named ORDER
PostPosted: Wed Mar 10, 2010 6:43 pm 
Newbie

Joined: Tue Mar 09, 2010 10:45 pm
Posts: 3
Oracle database:

Code:
create table radutest (
  id int primary key not null,
  "order" int default 0
  );
insert into radutest values (1, 1);
select id, "order" from radutest;

create table succeeded.
1 rows inserted
ID                     order                 
---------------------- ----------------------
1                      1                     

1 rows selected


No mysteries here, you just quote the reserved name. Can't Hibernate do the same?


Top
 Profile  
 
 Post subject: Re: Issue with column named ORDER
PostPosted: Wed Mar 10, 2010 9:30 pm 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
you can define like this
Code:
@Column(name = "`order`")


Top
 Profile  
 
 Post subject: Re: Issue with column named ORDER
PostPosted: Wed Mar 10, 2010 10:07 pm 
Newbie

Joined: Tue Mar 09, 2010 10:45 pm
Posts: 3
Thanks, it actually works using the @Column annotation and the quotes.


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.