-->
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: String concatenation of returned fields in HSQL
PostPosted: Wed Jan 12, 2005 11:04 am 
Senior
Senior

Joined: Tue Aug 03, 2004 2:11 pm
Posts: 142
Location: Somerset
Hibernate version 2.1.7

How do I do the equivalent of

SELECT FIELD A || FIELDB FROM TABLE

in HQL ?

When I try this

List list = getHibernateTemplate().find("select b.description2 || b.description3 from StandingDataRow a, StandingDataRow b" +
" where b.description1 = ? and decimal(b.linkedTableKey1) = a.comp_id.genid " +
"and b.comp_id.tabkey = ? and a.comp_id.tabkey = ? " +
"and a.comp_id.genid > 0 and a.description1 = ? and b.comp_id.genid > 0 ",args);


I get this:

org.springframework.orm.hibernate.HibernateQueryException: , expected in SELECT [select b.description2 || b.description3 from net.targetgroup.standingdata.StandingDataRow a, net.targetgroup.standingdata.StandingDataRow b where b.description1 = ? and decimal(b.linkedTableKey1) = a.comp_id.genid and b.comp_id.tabkey = ? and a.comp_id.tabkey = ? and a.comp_id.genid > 0 and a.description1 = ? and b.comp_id.genid > 0 ]; nested exception is net.sf.hibernate.QueryException: , expected in SELECT [select b.description2 || b.description3 from net.targetgroup.standingdata.StandingDataRow a, net.targetgroup.standingdata.StandingDataRow b where b.description1 = ? and decimal(b.linkedTableKey1) = a.comp_id.genid and b.comp_id.tabkey = ? and a.comp_id.tabkey = ? and a.comp_id.genid > 0 and a.description1 = ? and b.comp_id.genid > 0 ]
net.sf.hibernate.QueryException: , expected in SELECT [select b.description2 || b.description3 from net.targetgroup.standingdata.StandingDataRow a, net.targetgroup.standingdata.StandingDataRow b where b.description1 = ? and decimal(b.linkedTableKey1) = a.comp_id.genid and b.comp_id.tabkey = ? and a.comp_id.tabkey = ? and a.comp_id.genid > 0 and a.description1 = ? and b.comp_id.genid > 0 ]
at net.sf.hibernate.hql.SelectParser.token(SelectParser.java:169)
at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87)
at net.sf.hibernate.hql.ClauseParser.end(ClauseParser.java:114)
at net.sf.hibernate.hql.PreprocessingParser.end(PreprocessingParser.java:143)
at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:30)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:149)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:138)
at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:295)
at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1571)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1542)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at org.springframework.orm.hibernate.HibernateTemplate$25.doInHibernate(HibernateTemplate.java:546)
at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:243)
at org.springframework.orm.hibernate.HibernateTemplate.executeFind(HibernateTemplate.java:263)
at org.springframework.orm.hibernate.HibernateTemplate.find(HibernateTemplate.java:535)
at org.springframework.orm.hibernate.HibernateTemplate.find(HibernateTemplate.java:527)
at net.targetgroup.standingdata.StandingDataDAOHibernate.getRelatedTableByDesc1(StandingDataDAOHibernate.java:428)
at net.targetgroup.standingdata.StandingDataDAOTest.testRelatedTable(StandingDataDAOTest.java:106)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:41)
at java.lang.reflect.Method.invoke(Method.java:386)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:392)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:276)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:167)

_________________
On the information super B road


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 12, 2005 11:15 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
AFAIK this isn't possible.

Try
Code:
select b.description2, b.description3 ...

This will get you an Object array with the values of the two fields.

HTH
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 12, 2005 11:29 am 
Senior
Senior

Joined: Tue Aug 03, 2004 2:11 pm
Posts: 142
Location: Somerset
ernst_pluess wrote:
AFAIK this isn't possible.

Try
Code:
select b.description2, b.description3 ...

This will get you an Object array with the values of the two fields.

HTH
Ernst


OK, ta, I was trying to avod this approach for pure laziness, but can cope with it !

_________________
On the information super B road


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 12, 2005 4:08 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Does your database and dialect suppport a concat function? If so, use:

select concat(fielda, fieldb) from table


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 12, 2005 4:21 pm 
Senior
Senior

Joined: Tue Aug 03, 2004 2:11 pm
Posts: 142
Location: Somerset
steve wrote:
Does your database and dialect suppport a concat function? If so, use:

select concat(fielda, fieldb) from table


I don't want to do anything that makes my code database specific (this is very important for us) so I just dealt with two objects in an array in the end.

Ta anyway.

_________________
On the information super B road


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.