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?
bhomassAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.