-->
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.  [ 2 posts ] 
Author Message
 Post subject: Ways to do a Search based on Composed Object
PostPosted: Mon Mar 08, 2004 11:29 pm 
Newbie

Joined: Mon Mar 01, 2004 9:49 pm
Posts: 13
Hi,
Want to know how to search for a particular object based on composed object.

For Ex:
I have

ClassA representing TableA and ClassB representing TableB. THere is a many to one relationship between TableA and Table with column Variable1 i.e. Variable1 in Table B is foreign key to Variable1 in TableA.

public ClassA implements Serializable {
String var1;
String var2;
ClassB classB;
//getters and setters for all three variables.
}

public ClassB implements Serializable {
String variable1;
String variable2;
//getters and setters for all three variables.
}

mappingxml:
<hibernate-mapping>
<class name="test.classA">
<property name="var1">
<property name="var1">
<many-to-one name="classB" column="variable1">
</class>
<class name="test.classB">
<property name="variable1">
<property name="variable2">
</class>
</hibernate-mapping>

I am using Criteria object to do querying.

String var1Value="test";
String var2Value = "test2";
String variable1Value = "test3";
Criteria crit = sess.createCriteria(test.ClassA.class);
if(str1!=null)crit.add( Expression.like("var1", str1) );
if(str2!=null)crit.add( Expression.like("var2", str2) );
if(variable1Value!=null)crit.add( Expression.eq("classB", variable1Value) );

List result = crit.list();


Its actually printing the sql with correct final where clause which is something like
"select var1, var2, variable1 from classA as classA ......... where ...
and this.Variable1=?"
and then the error:
Error Creating QueryNo persister for: java.lang.String


The third if statement is giving me this error...?

Whats the bestway of doing these kind of searches..? I mean Searching for an object based on a variable of another object which it composes..?

Thanks
Rajeev.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 08, 2004 11:49 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 8:07 pm
Posts: 229
Location: Brisbane, Australia
Intead of:
Code:
crit.add( Expression.eq("classB", variable1Value)

You need to do something like:
Code:
crit.createCriteria("classB").add( Expression.eq("variable1", variable1Value) )

_________________
Cheers,
Shorn.


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