• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 721
  • Last Modified:

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?
0
bhomass
Asked:
bhomass
  • 3
  • 3
1 Solution
 
josephtsangCommented:
Did you notice any Select SQL statement being sent to the DB and logged at the moment the line is called?
0
 
bhomassAuthor Commented:
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.
0
 
josephtsangCommented:
Definitely not, I used these intermediate subclass a lot.

Could it be the typo there in the annotation of the class FlowElement? Something @Entity should be @javax.persistence.Entity.

If merely looking from the exception, that sounds related to some fundamental java standard library feature, such as ClassLoader, etc.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
bhomassAuthor Commented:
and you used for single table per hierarchy strategy using a discriminator column?
0
 
josephtsangCommented:
true
0
 
bhomassAuthor Commented:
I can not repeat the expert's suggestion, but I believe his comments are true.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now