Link to home
Start Free TrialLog in
Avatar of bhomass
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_TABLE)
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@DiscriminatorColumn(
    name="elementType",
    discriminatorType=DiscriminatorType.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("Diagram")
public class FlowDiagram extends FlowDiagramObject implements Serializable {

    @OneToMany(mappedBy="parentFlow", cascade={CascadeType.ALL})
      @Cache(usage= CacheConcurrencyStrategy.READ_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.READ_WRITE)
@DiscriminatorValue("CommandElement")
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?
Avatar of josephtsang
josephtsang

Did you notice any Select SQL statement being sent to the DB and logged at the moment the line is called?
Avatar of bhomass

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.
ASKER CERTIFIED SOLUTION
Avatar of josephtsang
josephtsang

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bhomass

ASKER

and you used for single table per hierarchy strategy using a discriminator column?
Avatar of bhomass

ASKER

I can not repeat the expert's suggestion, but I believe his comments are true.