You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Nimisha Gupta (JIRA)" <ji...@apache.org> on 2015/08/10 16:24:46 UTC

[jira] [Created] (OPENJPA-2604) How to persist multi level associations

Nimisha Gupta created OPENJPA-2604:
--------------------------------------

             Summary: How to persist multi level associations
                 Key: OPENJPA-2604
                 URL: https://issues.apache.org/jira/browse/OPENJPA-2604
             Project: OpenJPA
          Issue Type: Question
    Affects Versions: 1.1.0
            Reporter: Nimisha Gupta


I am trying to persist a three level association (i.e.Grandparent->Parents->Children)

A grandparent can have multiple parents and each parent can have multiple children.

I am trying to leverage the CASCADE option but am failing to do so.

Though I am able to persist in a two level association (i.e. Parent-> Children).

Could you please guide me as to what am I doing wrong in my entities?

GrandParent.java
--------------------------
@Column(name="O_ID")
private int oID;

@OneToMany(mappedBy = "grandparent", cascade = CascadeType.ALL, fetch = FetchType.EAGER, targetEntity = Parent.class)
	private Set<Parent> parents;

Parent.java
-------------
	@ManyToOne
	@JoinColumn(name = "O_ID", insertable = false, updatable = false)
	private Grandparent grandparent;

	@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "parent", targetEntity = Child.class)
	private Set<Child> children;

Child.java
-------------
@ManyToOne
	@JoinColumns({ @JoinColumn(name = "O_ID", referencedColumnName = "O_ID", insertable = false, updatable = false),
			@JoinColumn(name = "PRNT_ID", referencedColumnName = "PRNT_ID", insertable = false, updatable = false) })
	private Parent parent;

Grandparent table-> PK- {O_ID}
Parent table-> PK-{O_ID, PRNT_ID}
Child table-> PK-{O_ID, PRNT_ID, CHILD_ID}




--
This message was sent by Atlassian JIRA
(v6.3.4#6332)