Hello,
I am trying to do something very simple. I have different types of contact information like emails, addresses, phones etc stored in one table with a discriminator column.
I have a parent class called ContactInfo
Code:
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="CT_CODE", discriminatorType = DiscriminatorType.STRING)
@Table(name= "MX_ADDRESS")
public class ContactInfo extends Serializable
{
...
}
Each of the contact types have their own classes for eg
Code:
@Entity
@DiscriminatorValue("addr")
public class Address extends ContactInfo
{
...
@ManyToOne
@JoinColumn(name="MAST_ID")
private Master owner;
}
@Entity
@DiscriminatorValue("fax")
public class Fax extends ContactInfo
{
...
@ManyToOne
@JoinColumn(name="MAST_ID")
private Master owner;
}
Now when i try to get only the addresses it returns me back all the addresses
Code:
Session session = getHibernateTemplate().getSessionFactory()
.getCurrentSession();
Criteria criteria = session.createCriteria(Address.class);
criteria.list();
All the contact information belong to a person.
Code:
@Entity
@Table(name= "MX_MASTER")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="MAST_MEMEX_INDORG", discriminatorType= DiscriminatorType.STRING)
public class Master extends Serializable
{
...
@OneToMany(mappedBy="owner")
@Cascade({CascadeType.ALL, CascadeType.DELETE_ORPHAN})
protected Set<Address> addresses = new TreeSet<Address>();
}
@Entity
@DiscriminatorValue("I")
public class Individual extends Master
{
...
}
But now when i tried to go through the member it returns me back all the contact info even if i am just looking for addresses
Code:
Master o = (Master ) getHibernateTemplate().get(Master.class, new Long(714));
o.getAddresses().size();
I am not sure why is the discriminator column in Address not being used. Can any one help???
~s.