HiberNate Filter with annotaions in one to many mapping
I have a class Person which can have 4 type of addresses and there could be multiple number of adresses corresponding to a single type of address.
public class Person{
Set<Address> addresses;
}
public class Address{
private int phoneNumber;
private Type addressType;
}
public Enum Type{
Buisness,
Personal,
X,
Y
}
So what i want to implement is when a person object is populated List of Addesses of a particular type should be populated with a particular type of address. however i wish to specify which type of address to be populated at r开发者_如何学Cun time. i think its possible through hibernate Filter XML config's but i want to implement it with annotations only.
You can use @Filter annotations to filter out data at runtime.
public class Person{
@Filter(name="filterAddressType", condition=":addressType = addressType")
Set<Address> addresses;
}
And at runtime you can apply filter data via session as below:
session.enableFilter("filterAddressType").setParameter("addressType ", "Home");
精彩评论