bhomass
asked on
JPA Hibernate illegal access to loading collection
I have used hibernate annotation for a while, and am just now running into a problem when trying a slightly complicated mapping.
The class hierarchy is like this
// no @Entity annotation here
public abstract class Entity implements CommonEntity {
...
}
@javax.persistence.Entity
@Table(name="FLOW_ELEMENT" )
@Inheritance(strategy = InheritanceType.SINGLE_TAB LE)
@Cache(usage = CacheConcurrencyStrategy.R EAD_WRITE)
@DiscriminatorColumn(
name="elementType",
discriminatorType=Discrimi natorType. STRING
)
public abstract class FlowDiagramObject extends Entity implements Serializable {
@Id
@Column(name = "FLOW_ELEMENT_ID", precision = 22, scale = 0)
@GeneratedValue(strategy = GenerationType.AUTO)
protected long id;
.......
}
@javax.persistence.Entity
@DiscriminatorValue("Diagr am")
public class FlowDiagram extends FlowDiagramObject implements Serializable {
@OneToMany(mappedBy="paren tFlow", cascade={CascadeType.ALL})
@Cache(usage= CacheConcurrencyStrategy.R EAD_WRITE)
protected Set<FlowElement> elements = new HashSet<FlowElement>();
.....
}
@Entity
public abstract class FlowElement extends FlowDiagramObject {
@ManyToOne
@JoinColumn (name="parent_object_id")
protected FlowDiagram parentFlow; // only used to point to diagram element
......................
}
@javax.persistence.Entity
@Cache(usage = CacheConcurrencyStrategy.R EAD_WRITE)
@DiscriminatorValue("Comma ndElement" )
public class CommandElement extends FlowElement {
....
}
I am able to using HQL to get a FlowDiagram object, but when accessing its children
flowDiagram.getElements();
I get a illegal access to loading collection exception.
I am completely sure this is done inside the session, so that is not the problem. There must be something wrong with my mapping.
Anyone see the problem?
The class hierarchy is like this
// no @Entity annotation here
public abstract class Entity implements CommonEntity {
...
}
@javax.persistence.Entity
@Table(name="FLOW_ELEMENT"
@Inheritance(strategy = InheritanceType.SINGLE_TAB
@Cache(usage = CacheConcurrencyStrategy.R
@DiscriminatorColumn(
name="elementType",
discriminatorType=Discrimi
)
public abstract class FlowDiagramObject extends Entity implements Serializable {
@Id
@Column(name = "FLOW_ELEMENT_ID", precision = 22, scale = 0)
@GeneratedValue(strategy = GenerationType.AUTO)
protected long id;
.......
}
@javax.persistence.Entity
@DiscriminatorValue("Diagr
public class FlowDiagram extends FlowDiagramObject implements Serializable {
@OneToMany(mappedBy="paren
@Cache(usage= CacheConcurrencyStrategy.R
protected Set<FlowElement> elements = new HashSet<FlowElement>();
.....
}
@Entity
public abstract class FlowElement extends FlowDiagramObject {
@ManyToOne
@JoinColumn (name="parent_object_id")
protected FlowDiagram parentFlow; // only used to point to diagram element
......................
}
@javax.persistence.Entity
@Cache(usage = CacheConcurrencyStrategy.R
@DiscriminatorValue("Comma
public class CommandElement extends FlowElement {
....
}
I am able to using HQL to get a FlowDiagram object, but when accessing its children
flowDiagram.getElements();
I get a illegal access to loading collection exception.
I am completely sure this is done inside the session, so that is not the problem. There must be something wrong with my mapping.
Anyone see the problem?
Did you notice any Select SQL statement being sent to the DB and logged at the moment the line is called?
ASKER
I found the answer by experimenting.
The intermediate subclass FlowElement can not be abstract. Hiberate mapping fails otherwise. Unless someone knows how to tune mapping to allow for the abstract qualifier to remain.
The intermediate subclass FlowElement can not be abstract. Hiberate mapping fails otherwise. Unless someone knows how to tune mapping to allow for the abstract qualifier to remain.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
and you used for single table per hierarchy strategy using a discriminator column?
true
ASKER
I can not repeat the expert's suggestion, but I believe his comments are true.