-->
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.  [ 4 posts ] 
Author Message
 Post subject: HQL queries with "select null as ", cast(integer as string)
PostPosted: Thu Jun 17, 2010 10:35 pm 
Regular
Regular

Joined: Tue Feb 19, 2008 6:05 pm
Posts: 82
I have beans being populated using constructor based queries as follows.

session.createQuery("select new someBean(someProp1 as abc, someProp2 as bcd, null as cde, someProp3 as cde)
from someEntity ").list();

Why should this throws a null pointer exception?

The DB2 database does not seem to support the following:
"select (cast(integerProp as string)) from someEntity"

This casting should be database specific, but where do we add this? unlike a dialect class where you can add new functions. I exepected the above hql: cast(integerProp as string) to work as:

sql: rtrim(cast(cast(integerProp as character(200)) as varchar(200))
which works correctly as a DB2 sql query.

rather than cast(integerProp as varchar) which throws a DB2 exception

WHERE DO WE OVERRIDE THIS CONVERSION FOR DB2?

Regards
Rama


Last edited by pvradhakrishna on Thu Oct 07, 2010 5:55 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: HQL queries with "select null as ", cast(integer as string)
PostPosted: Mon Jun 21, 2010 6:38 pm 
Regular
Regular

Joined: Tue Feb 19, 2008 6:05 pm
Posts: 82
Is there no way to do a select null as ?, this is very useful in populating constructor based entities using the hql:
"select new somePojo(entityAlias.prop1, null, entityAlias.prop3) from someEntity entityAlias"

How do I write my custom cast(integer as string) logic for DB2 dialect?


Top
 Profile  
 
 Post subject: Re: HQL queries with "select null as ", cast(integer as string)
PostPosted: Sun Jul 04, 2010 2:45 pm 
Regular
Regular

Joined: Tue Feb 19, 2008 6:05 pm
Posts: 82
This was probably because the constructor data type (like BigDecimal) was expecting a non-null argument.


Top
 Profile  
 
 Post subject: casting as big decimal
PostPosted: Wed Oct 06, 2010 12:28 pm 
Regular
Regular

Joined: Tue Feb 19, 2008 6:05 pm
Posts: 82
Solution: if someone were to use a constructor query and one of the columns has to be casted to big decimal, or if you want to override of the constructor arguments to a default big decimal value,

org.hibernate.type.BigDecimalType suggests that the getName() is big_decimal so the usage is

new entity(.., cast(0.0 as big_decimal))

else, expect "Unable to locate appropriate constructor"


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