-->
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: @OneToMany - only get active employees?
PostPosted: Fri Feb 09, 2007 8:07 am 
Newbie

Joined: Fri Feb 09, 2007 7:50 am
Posts: 1
Hibernate version: 3.2

I am using hibernate annotations to map the relationship between a department and its employees.

On the Department object I only want the employees list to hold the active employees (the ones that have an endDate that is null), how do I do that?

Here is the code for the department and employee, without getters/setters:

public class Department implements Serializable {

@Id @Column(name="id")
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SEQ_GEN")
private long id;
@Column(nullable=false, length=128)
private String name;
@Column(length=255)
private String description;
@Column(name="created_date", nullable=false, updatable=false)
private Date createdDate;
@Column(name="end_date")
private Date endDate;

....
@OneToMany(mappedBy="department")
private List<Employee> employees;

}


public class Employee implements Serializable {

@Id @Column(name="id")
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SEQ_GEN")
private long id;
@Column(name="first_name", nullable=false)
private String firstName;
@Column(name="last_name", nullable=false)
private String lastName;
private String email;
@Column(name="created_date", nullable=false, updatable=false)
private Date createdDate;
@Column(name="end_date")
private Date endDate;

@ManyToOne
@JoinColumn(name="department_id")
private Department department;
...
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 09, 2007 3:53 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
either a collection filter, a @Filter or a @Where clause should help here

_________________
Emmanuel


Top
 Profile  
 
 Post subject: @filter is ignored.
PostPosted: Fri Jun 22, 2007 12:10 pm 
Newbie

Joined: Fri Jun 22, 2007 11:09 am
Posts: 2
I have a similar problem. I was able to get the @Where annotation work. But looks like Hibernate is ignoring the @filter annotation. Any reason why?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 22, 2007 1:57 pm 
Newbie

Joined: Fri Jun 22, 2007 11:09 am
Posts: 2
I was using EntityManager, I was able to enable filter through the following. It's confusing though.

Session hem = (Session) em.getDelegate();
hem.enableFilter("franchise_group");


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.