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: QueryByExample with associations ?
PostPosted: Mon Oct 08, 2007 11:07 am 
Newbie

Joined: Thu Oct 04, 2007 4:37 pm
Posts: 3
Hi ,

I'm trying to achieve: Get all employees with the given manager.

I am using hibernate Query By Example . But it is not returning any results.

Employee employee = new Employee();
employee.setEmployeeName("ABC");
employee.setManager(manager);

Criteria criteria = session.createCriteria(Employee.class).
add(Example.create(employee ).excludeZeroes());

if(employee .getManager() != null)
{
criteria.createCriteria("manager").add(
Example.create(employee .getManager()).excludeZeroes());

}


Here are my POJOs.


public Employee() extends Subordinate{
private String employeeName;
public void setEmployeeName(String employeeName){
this.employeeName = employeeName;
}
public void getEmployeeName(){
return this.employeeName;
}
}


public Manager(){
private String managerName;
public void setManagerName(String managerName){
this.managerName = managerName;
}
public String getManagerName(){
return this.managerName;
}

private List<Subordinate> subordinates;
public void setSubordinates (List subordinates){
this.subordinates = subordinates;
}
public void getSubordinates (){
return this.subordinates;
}
}

public Subordinate(){
private String subordinateName;
public void setSubordinateName(String subordinateName){
this.subordinateName= subordinateName;
}

public String getSubordinateName(){
return this.subordinateName;
}

private Manager manager;
public void setManager(Manager manager){
this.manager = manager;
}
public void getManager(){
return this.manager;
}
}

Can anybody help.

Thanks


Top
 Profile  
 
 Post subject: Re: QueryByExample with associations ?
PostPosted: Wed Oct 10, 2007 3:04 am 
Newbie

Joined: Wed Oct 10, 2007 2:33 am
Posts: 2
I believe Hibernate query by example should be simpler (like in other modern persistence engines). For example in db4o the corresponding native query would be:

Code:
List<Employee> employees = db.query(new Predicate<Employee>() {
                public boolean match(Employee candidate) {
                    return candidate.getManager().equals(manager);
                }
            }


Sorry for not directly answering your question!

Best regards.

german1


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.