-->
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: Criteria problem
PostPosted: Fri Oct 06, 2006 10:19 am 
Newbie

Joined: Fri Oct 06, 2006 10:10 am
Posts: 7
Hi all,

i´m newbie to hibernate, i´ve just initiate investigating the possibilities, there´s a lot of.

When i´m testing i´ve encoutered a problem (me), i´ve this mapping of 2 tables :


<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 4/Out/2006 15:22:37 by Hibernate Tools 3.2.0.beta7 -->
<hibernate-mapping>
<class name="enroll.pendingaccount.model.CtthubPendingAccounts"
table="CTTHUB_PENDING_ACCOUNTS" schema="edx_dba" catalog="edx0">
<composite-id name="id" class="enroll.pendingaccount.model.CtthubPendingAccountsId">
<key-property name="mailerId" type="int">
<column name="mailerID" precision="9" scale="0" />
</key-property>
<key-property name="accountId" type="string">
<column name="accountID" />
</key-property>
</composite-id>
<property name="status" type="byte">
<column name="status" not-null="true" />
</property>
<property name="userId" type="string">
<column name="UserId" length="40" not-null="true" />
</property>
<property name="createdAt" type="timestamp">
<column name="createdAt" length="23" not-null="true" />
</property>
<property name="updatedAt" type="timestamp">
<column name="updatedAt" length="23" not-null="true" />
</property>
<set name="ctthubAccountsAttribses" inverse="true">
<key>
<column name="mailerID" precision="9" scale="0" not-null="true" />
<column name="accountID" not-null="true" />
</key>
<one-to-many class="enroll.pendingaccount.model.CtthubAccountsAttribs" />
</set>
</class>
</hibernate-mapping>


and i´m trying to make a CtthubPendingAccountsDAO.findByExample() but the hibernate only looks at the direct properties of the class, here´s an examples what i´m trying to do:

accountId = 1; (part of the ID)
status = 0; (property of the class)

It ignores the accountID that i passed to the instance, but the status property is included in the query??

how can i do the Criteria to make the hibernate API to look into de ID property of the Class CtthubPendingAccounts.

can anyone help me??

cheers


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 06, 2006 10:22 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
show the method

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 06, 2006 10:26 am 
Newbie

Joined: Fri Oct 06, 2006 10:10 am
Posts: 7
The method have nothing special...

I don´t know how to do this kind of Criteria that i want to do...

but there it is:

public List findByExample(CtthubPendingAccounts instance) {

log.debug("finding CtthubPendingAccounts instance by example");
try {
List results = HibernateSessionFactory.currentSession().createCriteria(
"pendingaccount.model.CtthubPendingAccounts").add(
Example.create(instance)).list();

log.debug("find by example successful, result size: " + results.size());
return results;
} catch (RuntimeException re) {
log.error("find by example failed", re);
throw re;
}
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 06, 2006 10:50 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
I've never used that Example.create method, but hibernate usually requires you to specify whether or not an attribute you are searching by is inside a different pk class or not

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


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.