Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
2.4.1
-
None
-
None
Description
I have below two entities :
@Entity @Table(name = "CNTC_RLTNSHP") public class ContactRelationship implements Serializable { // Parent private static final long serialVersionUID = 1L; @Id @Column(name = "O_CNTC_RLTNSHP_ID", updatable = false) @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer contactRelationshipID; @Column(name = "O_WRK_ID") private Long odsID; @OneToMany(mappedBy = "phoneContactRelationship", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER, targetEntity = ContactRelationshipPhone.class) private List<ContactRelationshipPhone> contactRelationshipPhones; // Getters,setters,hashcode,equals --Child class @Entity @Table(name = "CNTC_RLTNSHP_PH") public class ContactRelationshipPhone implements Serializable { private static final long serialVersionUID = 1L; @EmbeddedId private ContactRelationshipPhonePK id; @Column(name = "CNTC_PH_NMBR_TXT") private String contactPhoneNumber; @Column(name = "PRMY_PH_INDCTR") private String contactPrimaryPhoneIndicator; @MapsId("contactRelationshipID") @ManyToOne @JoinColumn(name = "O_CNTC_RLTNSHP_ID", referencedColumnName = "O_CNTC_RLTNSHP_ID", insertable = false, updatable = false) private ContactRelationship phoneContactRelationship; public ContactRelationshipPhone() { } // Getters,setters,hashcode,equals -- Child class PK @Embeddable public class ContactRelationshipPhonePK implements Serializable { private static final long serialVersionUID = 1L; @Column(name = "O_CNTC_RLTNSHP_ID") private Integer contactRelationshipID; @Column(name = "PH_TYP_CD") private String phoneCode; @Column(name = "PH_TYP_TXT") private String phoneText; public ContactRelationshipPhonePK() { } // Getters,setters,hashcode,equals
The generated primary key is not set in child classes hence get SQL exception while inserting data in child tables
Exception in thread "main" <openjpa-2.2.3-SNAPSHOT-r422266:1715851 fatal store error> org.apache.openjpa.persistence.RollbackException: The transaction has been rolled back. See the nested exceptions for details on the errors that occurred. FailedObject: com.principal.scbu.ods.entity.worker.ContactRelationshipPhone@61b061b0 at org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImpl.java:594) at com.test.Test.main(Test.java:73) Caused by: <openjpa-2.2.3-SNAPSHOT-r422266:1715851 fatal general error> org.apache.openjpa.persistence.PersistenceException: The transaction has been rolled back. See the nested exceptions for details on the errors that occurred. FailedObject: com.principal.scbu.ods.entity.worker.ContactRelationshipPhone@61b061b0 at org.apache.openjpa.kernel.BrokerImpl.newFlushException(BrokerImpl.java:2352) at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:2189) at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:2087) at org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:2005) at org.apache.openjpa.kernel.LocalManagedRuntime.commit(LocalManagedRuntime.java:81) at org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1529) at org.apache.openjpa.kernel.DelegatingBroker.commit(DelegatingBroker.java:933) at org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImpl.java:570) ... 1 more Caused by: <openjpa-2.2.3-SNAPSHOT-r422266:1715851 fatal general error> org.apache.openjpa.persistence.PersistenceException: AN UPDATE, INSERT, OR SET VALUE IS NULL, BUT THE OBJECT COLUMN O_CNTC_RLTNSHP_ID CANNOT CONTAIN NULL VALUES {prepstmnt 1218201756 INSERT INTO XXX.CNTC_RLTNSHP_PH (PH_TYP_CD, PH_TYP_TXT, CNTC_PH_NMBR_TXT, PRMY_PH_INDCTR) VALUES (?, ?, ?, ?) [params=(null) null, (null) null, (String) E, (String) E]} [code=-407, state=23502]SQLCA OUTPUT[Errp=DSNXODM , Errd=12, 0, 0, -1, 0, 0] AN UPDATE, INSERT, OR SET VALUE IS NULL, BUT THE OBJECT COLUMN O_CNTC_RLTNSHP_ID CANNOT CONTAIN NULL VALUES THE DESCRIBE STATEMENT DOES NOT SPECIFY A PREPARED STATEMENT THE EXECUTE STATEMENT DOES NOT IDENTIFY A VALID PREPARED STATEMENT FailedObject: com.principal.scbu.ods.entity.worker.ContactRelationshipPhone@61b061b0 at org.apache.openjpa.jdbc.sql.DBDictionary.narrow(DBDictionary.java:4991) at org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException(DBDictionary.java:4957) at org.apache.openjpa.jdbc.sql.DB2Dictionary.newStoreException(DB2Dictionary.java:571) at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:136) at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:78) at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushAndUpdate(PreparedStatementManagerImpl.java:144) at org.apache.openjpa.jdbc.kernel.BatchingPreparedStatementManagerImpl.flushAndUpdate(BatchingPreparedStatementManagerImpl.java:79) at com.ibm.ws.persistence.jdbc.kernel.PreparedStatementManagerImpl.flushAndUpdate(PreparedStatementManagerImpl.java:63) at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushInternal(PreparedStatementManagerImpl.java:100) at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flush(PreparedStatementManagerImpl.java:88) at org.apache.openjpa.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:550) at org.apache.openjpa.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:106) at org.apache.openjpa.jdbc.kernel.BatchingConstraintUpdateManager.flush(BatchingConstraintUpdateManager.java:59) at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:113) at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:78) at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush(JDBCStoreManager.java:732) at org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:131) ... 8 more Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: AN UPDATE, INSERT, OR SET VALUE IS NULL, BUT THE OBJECT COLUMN O_CNTC_RLTNSHP_ID CANNOT CONTAIN NULL VALUES {prepstmnt 1218201756 INSERT INTO XXX.CNTC_RLTNSHP_PH (PH_TYP_CD, PH_TYP_TXT, CNTC_PH_NMBR_TXT, PRMY_PH_INDCTR) VALUES (?, ?, ?, ?) [params=(null) null, (null) null, (String) E, (String) E]} [code=-407, state=23502] at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:219) at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:195) at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.access$1000(LoggingConnectionDecorator.java:59) at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection$LoggingPreparedStatement.executeUpdate(LoggingConnectionDecorator.java:1134) at org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:275) at org.apache.openjpa.jdbc.kernel.JDBCStoreManager$CancelPreparedStatement.executeUpdate(JDBCStoreManager.java:1792) at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.executeUpdate(PreparedStatementManagerImpl.java:268) at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushAndUpdate(PreparedStatementManagerImpl.java:119) ... 19 more
Please find below persistence.xml
<?xml version="1.0" encoding="UTF-8"?> <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0"> <persistence-unit name="jpa-test" transaction-type="RESOURCE_LOCAL"> <class>com.principal.scbu.ods.entity.worker.ContactRelationship</class> <class>com.principal.scbu.ods.entity.worker.ContactRelationshipPhone</class> <class>com.principal.scbu.ods.entity.worker.ContactRelationshipPhonePK</class> <properties> <property name="openjpa.ConnectionDriverName" value="com.ibm.db2.jcc.DB2Driver" /> <property name="openjpa.ConnectionURL" value="jdbc:db2://host:port/dbname:retrieveMessagesFromServerOnGetMessage=true;" /> <property name="openjpa.ConnectionUserName" value="*****" /> <property name="openjpa.ConnectionPassword" value="*******" /> <property name="openjpa.jdbc.Schema" value="XXXX> <property name="openjpa.jdbc.DBDictionary" value="db2" /> <property name="openjpa.TransactionMode" value="local" /> <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/> <property name="openjpa.Compatibility" value="StrictIdentityValues=false,QuotedNumbersInQueries=true" /> <property name="openjpa.RuntimeUnenhancedClasses" value="0" /> <property name="openjpa.Log" value="DefaultLevel=WARN, Runtime=INFO, Tool=INFO, SQL=TRACE" /> <property name="openjpa.jdbc.MappingDefaults" value="jpa(ForeignKeyDeleteAction=restrict, JoinForeignKeyDeleteAction=restrict)" /> <property name="openjpa.jdbc.SchemaFactory" value="native(ForeignKeys=true)" /> <property name="openjpa.ConnectionFactoryProperties" value="PrintParameters=true" /> </properties> </persistence-unit> </persistence>
Please let me know if i have missed on something