-->
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: Example conjunction problem.
PostPosted: Tue May 12, 2009 8:30 am 
Newbie

Joined: Tue May 12, 2009 6:11 am
Posts: 1
First a small sketch of how the situation is :
I have a criteria that works, but now something needs to be added because the business changed.
Now the new thing needs to be added as an OR function over all the rest that already existed.
Example :
old : SELECT .... FROM .... WHERE A AND B AND C
new : SELECT .... FROM .... WHERE (A AND B AND C) OR D
This wouldn't be a problem if it where all normal restrictions. But with the use of Examples it seems to give a problem.

The code is just an altered version of my original code, because I can't place the original here, company policy.

Code:
Old code :
Criteria criteria = inSession.createCriteria(SomeObject1.class);
criteria.add(Restrictions.isNotNull("value1"));
criteria.add(Restrictions.eq("test", value2));
SomeObject2 object2 = new SomeObject2();
Example example1 = Example.create(object2).ignoreCase().enableLike(MatchMode.ANYWHERE);
criteria.createCriteria("someObject2").add(example1);


New code :
Criteria criteria = inSession.createCriteria(SomeObject1.class);
Conjunction conjunction1 = Restrictions.conjunction();
Conjunction conjunction2 = Restrictions.conjunction();
Disjunction disjunction = Restrictions.disjunction();
disjunction.add(conjunction1).add(conjunction2);
criteria.add(disjunction);

conjunction1.add(Restrictions.isNotNull("value1"));
conjunction1.add(Restrictions.eq("test", value2));
SomeObject2 object2 = new SomeObject2();
Example example1 = Example.create(object2).ignoreCase().enableLike(MatchMode.ANYWHERE);
// Problem is here how do you add that example to a conjunction, where you need to define that the example is of type "SomeObject2"?
//criteria.createCriteria("someObject2").add(example1);  //Old code before I added conjuctions
conjunction1.add(example1); // Gives a ClassCastException

// New Code the reason why I added conjuctions
SomeObject3 object3 = new SomeObject3();
Example example2 = Example.create(object3).ignoreCase().enableLike(MatchMode.ANYWHERE);
// Same problem here how do you define the type?
//criteria.createCriteria("someObject3").add(example2);
conjunction2.add(example2); // Gives a ClassCastException


So the question is how do you define, for an example you add to a conjunction, what the type of object it is?
Is this possible or is there an other solution?


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.