-->
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.  [ 1 post ] 
Author Message
 Post subject: Join problem
PostPosted: Thu Feb 21, 2008 7:08 am 
Newbie

Joined: Thu Feb 21, 2008 6:49 am
Posts: 1
Hi,

I have join problem between two tables.

Cod status table is:
K CO_BANK
K CO_STATUS
DE_STATUS
MacroOutcome and Cod status table is:
K CO_BANK
K CO_MACRO_OUTCOME
K CO_STATUS
CO_STATUS_NEXT

I success to join CO_STATUS using a Set definition, but I have a problem to join CO_STATUS_NEXT, probabily because this is not a key in our table.

I can't change the table definition.
I'd like to have the MacroOutcomeStatusContact like with this fields:
private KeyFieldOutcomeStatusContact id = new KeyFieldOutcomeStatusContact();
private String bankId = new String();
private String codeMacroOutcome = new String();
private String codeStatusContact = new String();
private String codeStatusContactNext = new String();
private Set statusContactOuts = new HashSet();
private Set statusContactOutsNext = new HashSet();

Some can help me?

Hibernate version:
3.0
Mapping documents:
<hibernate-mapping package="macroOutcomeStatusContact">
<class name="MacroOutcomeStatusContact" table="OUTCOMES">
<composite-id name="id" class="KeyFieldOutcomeStatusContact">
<key-property name="bankId" type="string" column="CO_BANK"/>
<key-property name="codeStatusContact" type="string" column="CO_STATUS"/>
</composite-id>
<property name="bankId" type="string" column="CO_BANK" insert="false" update="false"/>
<property name="codeMacroOutcome" type="string" column="CO_MACRO_OUTCOME"/>
<property name="codeStatusContact" type="string" column="CO_STATUS" insert="false" update="false"/>
<property name="codeStatusContactNext" type="string" column="CO_STATUS_NEXT"/>
<set name="statusContactOuts" inverse="true" lazy="false">
<key>
<column name="CO_BANK"/>
<column name="CO_STATUS"/>
</key>
<one-to-many class="StatusContact"/>
</set>
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
private List getQueryString(Session session, MacroOutcomeStatusContact macroOutcomeStatusContact) throws MisSevereException, XFRException
{
Map parameters = new HashMap();
boolean firstClause = true;
StringBuffer queryBuf
= new StringBuffer("from MacroOutcomeStatusContact as ch ");

if (macroOutcomeStatusContact.getBankId() != null && !"".equals(macroOutcomeStatusContact.getBankId())) {
queryBuf.append(firstClause ? " where " : " and ");
queryBuf.append("ch.bankId = :bankId");
parameters.put("bankId",macroOutcomeStatusContact.getBankId());
firstClause = false;
}
if (macroOutcomeStatusContact.getCodeMacroOutcome() != null && !"".equals(macroOutcomeStatusContact.getCodeMacroOutcome())) {
queryBuf.append(firstClause ? " where " : " and ");
queryBuf.append("ch.codeMacroOutcome = :codeMacroOutcome");
parameters.put("codeMacroOutcome",macroOutcomeStatusContact.getCodeMacroOutcome());
firstClause = false;
}
if (macroOutcomeStatusContact.getCodeStatusContact() != null && !"".equals(macroOutcomeStatusContact.getCodeStatusContact())) {
queryBuf.append(firstClause ? " where " : " and ");
queryBuf.append("ch.codeStatusContact = :codeStatusContact");
parameters.put("codeStatusContact",macroOutcomeStatusContact.getCodeStatusContact());
firstClause = false;
}
if (macroOutcomeStatusContact.getCodeStatusContactNext() != null && !"".equals(macroOutcomeStatusContact.getCodeStatusContactNext())) {
queryBuf.append(firstClause ? " where " : " and ");
queryBuf.append("ch.codeStatusContactNext = :codeStatusContactNext");
parameters.put("codeStatusContactNext",macroOutcomeStatusContact.getCodeStatusContactNext());
firstClause = false;
}

String hqlQuery = queryBuf.toString();
Query query = session.createQuery(hqlQuery);

// Set query parameter values

Iterator iter = parameters.keySet().iterator();
while (iter.hasNext()) {
String name = (String) iter.next();
Object value = parameters.get(name);
query.setParameter(name,value);
}

// Execute the query

return query.list();

Full stack trace of any exception that occurs:

Name and version of the database you are using:
DB2 9.n
The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.