Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

When Parent is saved, Child doesnt get saved.

942083Jun 7 2012 — edited Jun 7 2012
Hi,
I have 2 entities

public Parent()
{
int A;
int B;
Child child;

@ManyToOne(cascade = CascadeType.ALL,fetch = FetchType.EAGER)
@JoinColumn(name = "child_id", nullable = false)
public Child getChild() {
return this.child;
}
}

public Child()
{
int child_Id;
int Y;
Set<Parent> parents;

@OneToMany(fetch = FetchType.LAZY, mappedBy = "child")
public Set<Parent> getParents() {
return this.parents;
}

}

Then
Parent P = new Parent();
Child c = new Child();
....
I set values for both parent and child classes
p.setChild(c);

So when i save parent class

entityManager.persist(parent);

Ideally it should save the child. But it get the following error. My Entity Mapping were not manually written. They were generated by eclipse. So i presume as long as the database mapping is correct by entity mapping will also be correct.

+
Caused by: <openjpa-1.1.1-SNAPSHOT-r422266:807362 nonfatal store error> org.apache.openjpa.util.StoreException: ORA-02291: integrity constraint (PARENT_R03) violated - parent key not found
{prepstmnt 4234 INSERT INTO PARENT (A,B, CHILD_ID) VALUES (?, ?, ?, ?, ?, ?, ?) [ (null) null, (null) null, (BigDecimal) 58608]} [code=2291, state=23000]
FailedObject: com.ejb.entity.Parent@337261
at org.apache.openjpa.jdbc.sql.DBDictionary.narrow(DBDictionary.java:4207)
at org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException(DBDictionary.java:4171)
at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:102)
at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:72)
at kodo.jdbc.kernel.BatchingPreparedStatementManager.flushInternal(BatchingPreparedStatementManager.java:214)
at kodo.jdbc.kernel.BatchingPreparedStatementManager.flushInternal(BatchingPreparedStatementManager.java:112)
at kodo.jdbc.kernel.BatchingPreparedStatementManager.flush(BatchingPreparedStatementManager.java:72)
at kodo.jdbc.kernel.AutoOrderUpdateManager.flush(AutoOrderUpdateManager.java:84)
at kodo.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:68)
at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:89)
at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:72)
at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush(JDBCStoreManager.java:549)
at org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:130)
at org.apache.openjpa.datacache.DataCacheStoreManager.flush(DataCacheStoreManager.java:554)
at org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:130)
... 49 more
+
As you can see the CHILD_ID as been generated. But I think the order in which it gets commited is different. Please let me know if I need to change the configuration of my entity to make this work.
This post has been answered by gimbal2 on Jun 7 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 5 2012
Added on Jun 7 2012
4 comments
1,928 views