Hi.
I am using Hibernate 3.5.1 with JPA.
I have the following class structure. Getters, Setters, Properties, Methods ommited for clarity.
Code:
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "ORGANISATION_DISCRIMINATOR", discriminatorType = DiscriminatorType.INTEGER, length = 1)
@ForceDiscriminator
public abstract class Organisation() {
...
}
@Entity
@DiscriminatorValue("1")
public class Area extends Organisation {
@OneToMany(mappedBy = "area", cascade = CascadeType.ALL)
private List<Division> divisions;
}
@Entity
@DiscriminatorValue("2")
public class Division extends Organisation {
@ManyToOne
@JoinColumn(name = "PARENT_ID")
private Area area;
@OneToMany(mappedBy = "division", cascade = CascadeType.ALL)
private List<Team> teams;
}
@Entity
@DiscriminatorValue("3")
public class Team extends Organisation {
@ManyToOne
@JoinColumn(name = "PARENT_ID")
private Division division;
}
These are the only classes in my system which use the SINGLE_TABLE mechanism, and it has been designed this way for a specific purpose.
I have a strange problem where the fetching of entities only works SOME of the time.
If I call:
this.entityManager.find(Organisation.class, organisationId);
Some of the time it works, and the rest of the time I get:
javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: could not set a field value by reflection setter of entity.jpa.Division.area.
I thought the ForceDiscriminator would solve it as I had found in some previous posts, but it has not.
I just do not understand why it only fails some of the time. Is it an issue with the entities being cached in a certain way maybe? I know the SINGLE_TABLE mechanism is not ideal, but it is in the design for a reason and I would like to try and resolve it as best I can.
Many Thanks
Chris