title: Caused by: javax.persistence.PersistenceException: Insert of object
body: <p>SRAssignment.java</p>
  
  <pre><code>@Entity
  @Table(name="SR_ASSIGNEMENT", uniqueConstraints= { @UniqueConstraint
  (columnNames="SRAID")})
  @SequenceGenerator(name="SRASSIGNMENT_SEQUENCE", initialValue=1, allocationSize=1)
  public class SRAssignment implements Serializable{
  
  @Id @GeneratedValue(strategy=GenerationType.SEQUENCE, 
  generator="SRASSIGNMENT_SEQUENCE")
  @Column(name="SRAID", nullable=false)
  private long sraId;
  
  @ManyToOne(fetch=FetchType.LAZY)
  @JoinColumn(name="EMPNO")
  private Employee employee;
  
  @OneToOne(fetch=FetchType.EAGER, mappedBy="srNo", optional=false)
  private ServiceRequest serviceRequest;
  
  @ManyToOne(fetch=FetchType.LAZY)
  @JoinColumn(name="assignedBy")
  private Employee assignedBy;
  
  @Column(name="ASSIGNEDON")
  @Temporal(TemporalType.TIMESTAMP) 
  private Date assignedOn;
  
  @OneToOne(fetch=FetchType.LAZY, optional=true, mappedBy="slotNo")
  private ScheduleSlot startSlot;
  
  @OneToOne(fetch=FetchType.LAZY , optional=true, mappedBy="slotNo")
  private ScheduleSlot expectedEndSlot;
  
  @OneToOne(fetch=FetchType.LAZY , optional=true, mappedBy="slotNo")
  private ScheduleSlot actualEndSlot;
  
  @Column(name="SRA_COMMENT", nullable=true)
  private String comment;
  
  @Column(name="ATTACHMENT", nullable=true)
  private Object attachment;
  
  ....
  </code></pre>
  
  <p>ServiceRequest.java</p>
  
  <pre><code>@Entity
  @Table(name="SERVICE_REQUEST", uniqueConstraints = {@UniqueConstraint(columnNames=     
  {"SRNO"})})
  @SequenceGenerator(name="SERVICE_REQUEST_SEQUENCE", initialValue=1, allocationSize=100)
  public class ServiceRequest implements Serializable {
  
  @Id @GeneratedValue(strategy=GenerationType.SEQUENCE, 
  generator="SERVICE_REQUEST_SEQUENCE")
  @Column(name="SRNO",  nullable=false)
  private long srNo;
  
  @Column(name="DESCRIPTION")
  private String description;
  
  @Column(name="STATUS") 
  private int status;
  
  
  @ManyToOne(fetch=FetchType.LAZY)
  @JoinColumn(name="CUSTNO", referencedColumnName="CustNO")
  private Customer customer;
  
  @Column(name="DATECREATED")
  private Date dateCreated;
  
  @Column(name="DATEUPDATED")
  private Date dateUpdated;
  ...
  
  
  ServiceRequest request = workPersistence.getRequestById(assigner.getRequestId());
  Employee employee = workPersistence.getEmployeeById(assigner.getTechnician());
  Employee manager = workPersistence.getEmployeeById(assigner.getAssignedBy());
  SRAssignment assignment = new SRAssignment();
  
  assignment.setEmployee(employee);
  assignment.setAssignedBy(manager);
  assignment.setServiceRequest(request);
  assignment.setAssignedOn(Calendar.getInstance().getTime());
  
  EntityManager em = entityManagerFactory.createEntityManager();
  EntityTransaction tx = em.getTransaction();
  tx.begin();
  em.persist(assignment);
  em.refresh(assignment);
  System.out.println("refresh assignment, now commiting...");
  tx.commit();
  </code></pre>
  
  <p>Error I get is:</p>
  
  <p>refresh assignment, now commiting...
  javax.persistence.RollbackException: Transaction failed to commit
          at org.datanucleus.api.jpa.JPAEntityTransaction.commit(JPAEntityTransaction.java:118)
          at com.ge.dsp.iwork.persistence.JpaWorkPersistence.assignRequest(JpaWorkPersistence.java:417)
          at com.ge.dsp.iwork.impl.WorkServiceImpl.getRequestAssigned(WorkServiceImpl.java:146)
          at com.ge.dsp.iwork.impl.WorkServiceImpl.assignRequest(WorkServiceImpl.java:112)
          at com.ge.dsp.iwork.test.WorkServiceTest.testServiceRequestAssignment(WorkServiceTest.java:85)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:597)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1581)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1522)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
          at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
          at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
          at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
          at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
          at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:609)
          at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
          at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:69)
          at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:355)
          at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
          at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:320)
          at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:132)
          at java.lang.Thread.run(Thread.java:662)
  Caused by: javax.persistence.PersistenceException: Insert of object "com.ge.dsp.iwork.entity.SRAssignment@7edab86b" using statement <strong>"INSERT INTO SR_ASSIGNEMENT (ASSIGNEDBY,SRA_COMMENT,EMPNO,ASSIGNEDON,SRAID) VALUES (?,?,?,?,?)" failed
  : ORA-01400: cannot insert NULL into ("DSP_QA_4"."SR_ASSIGNEMENT"."SRNO")</strong></p>
  
  <pre><code>    at org.datanucleus.api.jpa.NucleusJPAHelper.getJPAExceptionForNucleusException(NucleusJPAHelper.java:270)
      at org.datanucleus.api.jpa.JPAEntityTransaction.commit(JPAEntityTransaction.java:116)
      ... 25 more
  </code></pre>
  
  <p>Caused by: java.sql.SQLIntegrityConstraintViolationException: ORA-01400: cannot insert NULL into ("DSP_QA_4"."SR_ASSIGNEMENT"."SRNO")</p>
  
  <pre><code>    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:439)
      at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:395)
      at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:802)
      at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:436)
      at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:186)
      at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:521)
      at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:205)
      at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:1008)
      at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1307)
      at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3449)
      at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3530)
      at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeUpdate(OraclePreparedStatementWrapper.java:1350)
      at org.datanucleus.store.rdbms.datasource.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
      at org.datanucleus.store.rdbms.datasource.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
      at org.datanucleus.store.rdbms.SQLController.executeStatementUpdate(SQLController.java:419)
      at org.datanucleus.store.rdbms.request.InsertRequest.execute(InsertRequest.java:411)
      at org.datanucleus.store.rdbms.RDBMSPersistenceHandler.insertTable(RDBMSPersistenceHandler.java:166)
      at org.datanucleus.store.rdbms.RDBMSPersistenceHandler.insertObject(RDBMSPersistenceHandler.java:142)
      at org.datanucleus.state.JDOStateManager.internalMakePersistent(JDOStateManager.java:2377)
      at org.datanucleus.state.JDOStateManager.flush(JDOStateManager.java:3769)
      at org.datanucleus.ObjectManagerImpl.flushInternalWithOrdering(ObjectManagerImpl.java:3884)
      at org.datanucleus.ObjectManagerImpl.flushInternal(ObjectManagerImpl.java:3807)
      at org.datanucleus.ObjectManagerImpl.flush(ObjectManagerImpl.java:3747)
      at org.datanucleus.ObjectManagerImpl.preCommit(ObjectManagerImpl.java:4137)
      at org.datanucleus.ObjectManagerImpl.transactionPreCommit(ObjectManagerImpl.java:428)
      at org.datanucleus.TransactionImpl.internalPreCommit(TransactionImpl.java:400)
      at org.datanucleus.TransactionImpl.commit(TransactionImpl.java:288)
      at org.datanucleus.api.jpa.JPAEntityTransaction.commit(JPAEntityTransaction.java:103)
      ... 25 more
  </code></pre>
  
  <p><strong>Why it doesnt get serviceRequest information and doesnot get SRNO to insert in the assignment?
  Also On the same relation when I attempt following :</strong></p>
  
  <pre><code>EntityManager em = entityManagerFactory.createEntityManager();
  Query query = em
  .createQuery(
  "SELECT assignment FROM SRAssignment assignment WHERE assignment.sraId = :sraId")
              .setParameter("sraId", new Long(assignmentId));
  List&lt;SRAssignment&gt; assignments = query.getResultList();
  SRAssignment sra = (SRAssignment) assignments.get(0);
      System.out.println(sra.getSraId());
      System.out.println(sra.getEmployee().getEmpNo());
      System.out.println("________________________________________");
      System.out.println(sra.getServiceRequest().getSrNo());
      System.out.println();
      em.close();
  </code></pre>
  
  <p>As soon as I hit the line 
          <strong>System.out.println(sra.getServiceRequest().getSrNo());</strong></p>
  
  <p>I get error as:
      <strong><em>_</em>__<em>_</em>__<em>_</em>__<em>_</em>__<em>_</em>__<em>_</em>__<em>_</em>___</strong>
  Exception in thread "SpringOsgiExtenderThread-88" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testGetAssignmentById' defined in URL [bundle://178.33:0/META-INF/spring/module-context.xml]: Inv
  ocation of init method failed; nested exception is javax.persistence.PersistenceException: Cannot perform operation "==" on org.datanucleus.store.rdbms.sql.expression.ObjectExpression@843249a and org.datanucleus.store.rdbms.sql.express
  ion.NumericExpression@7017feb2
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
          at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
          at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
          at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
          at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
          at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:609)
          at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
          at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:69)
          at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:355)
          at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
          at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:320)
          at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:132)
          at java.lang.Thread.run(Thread.java:662)
  Caused by: javax.persistence.PersistenceException: Cannot perform operation "==" on org.datanucleus.store.rdbms.sql.expression.ObjectExpression@843249a and org.datanucleus.store.rdbms.sql.expression.NumericExpression@7017feb2
          at org.datanucleus.api.jpa.NucleusJPAHelper.getJPAExceptionForNucleusException(NucleusJPAHelper.java:302)
          at org.datanucleus.api.jpa.JPAAdapter.getApiExceptionForNucleusException(JPAAdapter.java:898)
          at org.datanucleus.state.JDOStateManager.isLoaded(JDOStateManager.java:1736)
          at com.ge.dsp.iwork.entity.SRAssignment.jdoGetserviceRequest(SRAssignment.java)
          at com.ge.dsp.iwork.entity.SRAssignment.getServiceRequest(SRAssignment.java:151)
          at com.ge.dsp.iwork.persistence.JpaWorkPersistence.getAssignmentsByAssignmentId(JpaWorkPersistence.java:462)
          at com.ge.dsp.iwork.test.WorkServiceTest.testGetAssignmentById(WorkServiceTest.java:59)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:597)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1581)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1522)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
          ... 14 more
  Caused by: org.datanucleus.store.rdbms.sql.expression.IllegalExpressionOperationException: Cannot perform operation "==" on org.datanucleus.store.rdbms.sql.expression.ObjectExpression@843249a and org.datanucleus.store.rdbms.sql.express
  ion.NumericExpression@7017feb2
          at org.datanucleus.store.rdbms.sql.expression.SQLExpression.eq(SQLExpression.java:383)
          at org.datanucleus.store.rdbms.sql.expression.ObjectExpression.eq(ObjectExpression.java:217)
          at org.datanucleus.store.rdbms.sql.SQLStatement.getJoinConditionForJoin(SQLStatement.java:1232)
          at org.datanucleus.store.rdbms.sql.SQLStatement.join(SQLStatement.java:1151)
          at org.datanucleus.store.rdbms.sql.SQLStatement.leftOuterJoin(SQLStatement.java:892)
          at org.datanucleus.store.rdbms.sql.SQLStatement.leftOuterJoin(SQLStatement.java:848)
          at org.datanucleus.store.rdbms.sql.SQLStatementHelper.addJoinForOneToOneRelation(SQLStatementHelper.java:995)
          at org.datanucleus.store.rdbms.sql.SQLStatementHelper.selectMemberOfSourceInStatement(SQLStatementHelper.java:839)
          at org.datanucleus.store.rdbms.request.FetchRequest.processMembersOfClass(FetchRequest.java:488)
          at org.datanucleus.store.rdbms.request.FetchRequest.(FetchRequest.java:166)
          at org.datanucleus.store.rdbms.RDBMSPersistenceHandler.getFetchRequest(RDBMSPersistenceHandler.java:339)
          at org.datanucleus.store.rdbms.RDBMSPersistenceHandler.fetchObject(RDBMSPersistenceHandler.java:316)
          at org.datanucleus.state.JDOStateManager.loadFieldsFromDatastore(JDOStateManager.java:1634)
          at org.datanucleus.state.JDOStateManager.loadSpecifiedFields(JDOStateManager.java:1236)
          at org.datanucleus.state.JDOStateManager.isLoaded(JDOStateManager.java:1724)
          ... 25 more</p>