-->
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.  [ 7 posts ] 
Author Message
 Post subject: Is it possible to create a pseudo-column?
PostPosted: Fri May 16, 2008 3:51 pm 
Newbie

Joined: Tue May 06, 2008 5:01 pm
Posts: 3
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
Hibernate 3.0 final
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.abcd.webservices.servicename.dao.hibernate">
<class name="InformationRequestedAtDetailLevel" table="INTRNL_AND_EXTRNL_DETL">
<composite-id>
<key-property name="ieId" column="intrnl_and_extrnl_id" />
<key-property name="ieSlNumber" column="intrnl_and_extrnl_sl_nbr" />
<key-property name="ieOcNumber" column="intrnl_and_extrnl_oc_nbr" />
<key-property name="ieTabCode" column="intrnl_and_extrnl_tab_cd" />
<key-property name="ieItemCode" column="intrnl_and_extrnl_itm_cd" />
</composite-id>
<property name="ieVendCode" column="intrnl_and_extrnl_vend_cd"/>
<property name="ieDetailDesc" column="intrnl_and_extrnl_detail_desc"/>

<query name="ByManyParameters">
select ieTabDetail
from InformationRequestedAtDetailLevel as ieTabDetail
where
ieTabDetail.ieId = :ieId and
ieTabDetail.ieSlNumber = :ieSlNumber and
ieTabDetail.ieOcNumber = :ieOcNumber and
ieTabDetail.ieVendCode = :ieVendCode and
ieTabDetail.ieTabCode = :ieTabCode
</query>
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
SessionFactory is setup via Spring's applicationContext and Spring managed data source. The named query is run via the following method--

private Collection _findIntExtList(MyBusinessObject mBo) {
return getHibernateTemplate().findByNamedQueryAndNamedParam(
"com.abcd.webservices.servicename.dao.hibernate.InformationRequestedAtDetailLevel.ByManyParameters",
new String[] {"ieId", "ieSlNumber", "ieOcNumber", "ieVendCode", "ieTabCode" },
new Object[] {mBo.getIeId(), mBo.getIeSlNumber(), mBo.getIeOcNumber(), mBo.ieVendCode(), mBo.ieTabCode()}
);
}


Full stack trace of any exception that occurs:
Not Applicable

Name and version of the database you are using:
64-Bit DB2 9.1.4 running on AIX

The generated SQL (show_sql=true):
Not Applicable

Debug level Hibernate log excerpt:
Not Applicable

Problems with Session and transaction handling?
No

The question:
I'm writing a web service where I'll run a query via HQL named query. This query gets me a collection of objects that contain code and description. What I have to send back to the client is an array (or collection) of string that contains code + "-" + description format of what I got back from the query. I currently loop thru something like this (look at the while loop).

public Collection theDaoFindCaller(MyBusinessObject mBo) {

Collection ieTabDetailArrayList = new ArrayList();

Collection infoAtDetailLevel = _findIntExtList(mBo);

Iterator infoAtDetailLevelIt = infoAtDetailLevel.iterator();
while (infoAtDetailLevelIt.hasNext()) {
InformationRequestedAtDetailLevel infoReqAtDetLevel = (InformationRequestedAtDetailLevel)infoAtDetailLevelIt.next();
ieTabDetailArrayList.add(infoReqAtDetLevel.getIeItemCode() + "-" + infoReqAtDetLevel.getIeDetailDesc());
}
return ieTabDetailArrayList;
}

Can I some how avoid the loop that I have to go thru to concatenate two strings and have hibernate generate as a pseudo-column on-the-fly. With JDBC, I could have added this pseud-column to my selection column list and have added a field at the row mapper level, so I wouldn't have to do anything more.

I searched for the forum and google'd for an appropriate article, without luck. I appreciate if some one could send me some kind of try-out-solutions or links that could have more information, that would be very helpful.

Thanks for your time!

_________________
<Murugan/>


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 19, 2008 12:51 am 
Senior
Senior

Joined: Mon Feb 25, 2008 1:48 am
Posts: 191
Location: India
You could use formula for the property that you want to represent as a pseudo property.

Here is a sample
http://www.java2s.com/Code/Java/Hibernate/ColumnFormulaStringConcatenate.htm

Hope it helps!

_________________
Sukirtha


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 19, 2008 12:51 am 
Senior
Senior

Joined: Mon Feb 25, 2008 1:48 am
Posts: 191
Location: India
You could use formula for the property that you want to represent as a pseudo property.

Here is a sample
http://www.java2s.com/Code/Java/Hibernate/ColumnFormulaStringConcatenate.htm

Hope it helps!

_________________
Sukirtha


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 19, 2008 12:52 am 
Senior
Senior

Joined: Mon Feb 25, 2008 1:48 am
Posts: 191
Location: India
You could use formula for the property that you want to represent as a pseudo property.

Here is a sample
http://www.java2s.com/Code/Java/Hibernate/ColumnFormulaStringConcatenate.htm

Hope it helps!

_________________
Sukirtha


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 19, 2008 12:54 am 
Senior
Senior

Joined: Mon Feb 25, 2008 1:48 am
Posts: 191
Location: India
Ooops... Looks like I ended posting multiple times. Sorry!

_________________
Sukirtha


Top
 Profile  
 
 Post subject: Thanks for the help
PostPosted: Tue May 27, 2008 5:57 pm 
Newbie

Joined: Tue May 06, 2008 5:01 pm
Posts: 3
Thank you very much for the help Sukirtha!

I could use the formula attribute with the concatenated attribute I needed. DB2 didn't recognize the concat with more than two parameters, so I had to use Column1 || '-' || Column2 formula to get the concatenated string.

Once again, thanks for the quick help.

_________________
<Murugan/>


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 28, 2008 11:44 pm 
Senior
Senior

Joined: Mon Feb 25, 2008 1:48 am
Posts: 191
Location: India
Happy I could help. Also remember to rate useful posts. It really helps the poster as well as others cuz it would show that the solution really helped. :)

_________________
Sukirtha


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