-->
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.  [ 8 posts ] 
Author Message
 Post subject: how implement a find by Example usefull also for id
PostPosted: Mon Jun 18, 2007 10:58 am 
Beginner
Beginner

Joined: Thu Jan 20, 2005 1:45 pm
Posts: 49
hi all
I noticed by hibernate reference that it's impossible getting pojo by example when in the example is specified just the id.
I implemented this (does not work of course by id):

public Collection findByExample(Object example) throws PersistenceException {
log.info("findByExample...");
Collection collection;
try {

Criteria crit = HibernateSessionFactory.getSession()
.createCriteria(mappedClass);
collection = crit.add(Example.create(example).enableLike(MatchMode.EXACT)).list();

} catch (HibernateException ex) {
throw new PersistenceException(ex);
}
return collection;
}

I need a function that does the find by example also when in the example is specified just the id!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 18, 2007 11:10 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Code:
if(example.id != null) {
   //query by id
}
else {
  //your existing thing
}

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 18, 2007 11:19 am 
Beginner
Beginner

Joined: Thu Jan 20, 2005 1:45 pm
Posts: 49
are u sure example.id exists?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 18, 2007 11:32 am 
Beginner
Beginner

Joined: Thu Jan 20, 2005 1:45 pm
Posts: 49
emmanuel wrote:
Code:
if(example.id != null) {
   //query by id
}
else {
  //your existing thing
}


does not exist Example.id !


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 18, 2007 6:20 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
example is your the object in your method signature

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 19, 2007 3:16 am 
Beginner
Beginner

Joined: Thu Jan 20, 2005 1:45 pm
Posts: 49
emmanuel wrote:
example is your the object in your method signature

But i need a generic function for a generic object.
That's my problem.Did u see my function? I pass it a generic object and i need to recognize the id.
Any idea?
Regards


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 19, 2007 5:26 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You can look for the class medatada API in the SessionFactory

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: how implement a find by Example usefull also for id
PostPosted: Sun May 30, 2010 4:35 am 
Newbie

Joined: Fri May 14, 2010 5:51 pm
Posts: 8
Hi all,

Plz just want to know if this is resolved in recent versions of Hibernate.

Irshad


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