-->
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.  [ 10 posts ] 
Author Message
 Post subject: Problem with formula
PostPosted: Sat Nov 06, 2004 4:07 pm 
Newbie

Joined: Mon Sep 29, 2003 5:56 am
Posts: 10
Location: Belgrade, Serbia
I am using Hibernate 2.1.6 with SQL Server. I have following property in my mapping file (I want to convert decimal column to date):
Code:
<property formula="CAST(MODIFIED as datetime) - 2" name="modified" type="java.util.Date"/>


This formula is valid sql expression in SQL Server. However, Hibernate generates:
Code:
CAST(badgeacces0__1_.MODIFIED badgeacces0__1_.as badgeacces0__1_.datetime) -2 as f6_

instead of something like:
Code:
CAST(badgeacces0__1_.MODIFIED as datetime) -2 as f6_


Why Hibernate appends table alias to reserved words? Is it possible to prevent this? Am I doing something wrong?

Thanks in advance,
Dejan


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 06, 2004 4:12 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
try changing
Code:
<property formula="CAST(MODIFIED as datetime) - 2" name="modified" type="java.util.Date"/>



to
Code:
<property formula="(CAST(MODIFIED as datetime) - 2)" name="modified" type="java.util.Date"/>

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 06, 2004 5:51 pm 
Newbie

Joined: Mon Sep 29, 2003 5:56 am
Posts: 10
Location: Belgrade, Serbia
It does not help. The same sql is generated except this time sql expression is in braces.

Regards,
Dejan


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 06, 2004 6:25 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
ok debug with hibernate source, you may be able to extend some dialect

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 06, 2004 6:34 pm 
Newbie

Joined: Mon Sep 29, 2003 5:56 am
Posts: 10
Location: Belgrade, Serbia
anthony wrote:
ok debug with hibernate source, you may be able to extend some dialect


OK. Can you give me some hints. How Hibernate knows what are reserved words for some dialect? Or how it decide what to prefix with table aliases?

Thanks in advance,
Dejan


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 06, 2004 8:26 pm 
Newbie

Joined: Mon Sep 29, 2003 5:56 am
Posts: 10
Location: Belgrade, Serbia
I did hacked a little and now it works. I have created new Dialect by extending SqlServerDialect, and I have registered 'as' and 'datetime' keywords as functions so Template.renderWhereStringTemplate() method does not prefix them with table alias. It is ugly but works :)

However, I think that 'as' is standard sql keyword that should be in KEYWORDS map of net.sf.hibernate.sql.Template class. Also, isIdentifier() method should be little smarter and check if token is not reserved word for given dialect. That way hacks like the one I have done would not be needed!

Regards,
Dejan


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 07, 2004 4:06 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
be carefull test an hql like this:

select obj from Object as obj and tell me if it works

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 07, 2004 5:07 am 
Newbie

Joined: Mon Sep 29, 2003 5:56 am
Posts: 10
Location: Belgrade, Serbia
anthony wrote:
be carefull test an hql like this:

select obj from Object as obj and tell me if it works


Yes it does work (with custom dialect). I haven't tried to change net.sf.hibernate.sql.Template class to add things I have explained in previous post.

Regards,
Dejan


Top
 Profile  
 
 Post subject: Re: Problem with formula
PostPosted: Tue Aug 07, 2012 6:55 am 
Newbie

Joined: Mon Jun 25, 2012 10:52 am
Posts: 2
Is there any chance for this problem to be corrected. I'm using Hibernate 3.6.10 and I'm still facing this aliasing issue when mapping many-to-one with formula.
Code:
<formula>cast(dest as integer)</formula>
is making the following sql query :
Code:
cast(this_.dest as this_.integer)


Regards

Yoann


Top
 Profile  
 
 Post subject: Re: Problem with formula
PostPosted: Thu Apr 04, 2013 1:50 pm 
Newbie

Joined: Thu Apr 04, 2013 1:45 pm
Posts: 1
hi all,

I found the solution, just use double-quote around the reserved word. For example:

Code:
cast(my_date as "date")


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