-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Getting error while saving a list object
PostPosted: Sun Jul 31, 2016 2:35 pm 
Newbie

Joined: Tue Apr 19, 2016 6:24 am
Posts: 5
Hi Guys,

I have below two tables

Parent table:

Code:
package com.hibernatepojo;

import java.util.Date;
import java.util.List;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name="transaction")
@Access(value=AccessType.PROPERTY)
public class NewTransaction {
   private transient long txnId;
   private Date txnCreatedDttm;
   private Date txnCompletedDate;
   private String txnCreatedBy;
   private String txnOrderId;
   
   private List<TxnNetworkObject> txnNetworkObject;

   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name="txn_id")
   public long getTxnId() {
      return txnId;
   }

   public void setTxnId(long txnId) {
      this.txnId = txnId;
   }

   @Temporal(TemporalType.TIMESTAMP)
   @Column(name="txn_created_dttm")
   public Date getTxnCreatedDttm() {
      return txnCreatedDttm;
   }

   public void setTxnCreatedDttm(Date txnCreatedDttm) {
      this.txnCreatedDttm = txnCreatedDttm;
   }

   @Temporal(TemporalType.TIMESTAMP)
   @Column(name="txn_completed_dttm")
   public Date getTxnCompletedDate() {
      return txnCompletedDate;
   }

   public void setTxnCompletedDate(Date txnCompletedDate) {
      this.txnCompletedDate = txnCompletedDate;
   }
   
   @Column(name="txn_created_by")
   public String getTxnCreatedBy() {
      return txnCreatedBy;
   }

   public void setTxnCreatedBy(String txnCreatedBy) {
      this.txnCreatedBy = txnCreatedBy;
   }

   @Column(name="txn_order_id")
   public String getTxnOrderId()
   {
      return txnOrderId;
   }
   
   public void setTxnOrderId(String txnOrderId)
   {
      this.txnOrderId = txnOrderId;
   }

   @OneToMany(cascade = CascadeType.ALL,fetch=FetchType.LAZY)
    @JoinColumn(name = "tno_id")
   public List<TxnNetworkObject> getTxnNetworkObject() {
      return txnNetworkObject;
   }

   public void setTxnNetworkObject(List<TxnNetworkObject> txnNetworkObject) {
      this.txnNetworkObject = txnNetworkObject;
   }
}


and a list child class as below :

Code:
package com.bt.ngae.hibernatepojo;

import java.util.Date;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name = "txn_network_object")
@Access(value = AccessType.PROPERTY)
public class TxnNetworkObject {

   private long tnoId;
   private String tnoActivationData;
   private String tnoRollbackData;
   private Date tnoCreatedDttm;
   private String tnoErrorCode;
   private String tnoErrorTxt;
   private String tnoStatus;

   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   @Column(name = "tno_id")
   public long getTnoId() {
      return tnoId;
   }
   public void setTnoId(long tnoId) {
      this.tnoId = tnoId;
   }

   @Lob
   @Column(name = "tno_activation_data")
   public String getTnoActivationData() {
      return tnoActivationData;
   }
   public void setTnoActivationData(String tnoActivationData) {
      this.tnoActivationData = tnoActivationData;
   }

   @Lob
   @Column(name = "tno_rollback_data")
   public String getTnoRollbackData() {
      return tnoRollbackData;
   }
   
   public void setTnoRollbackData(String tnoRollbackData) {
      this.tnoRollbackData = tnoRollbackData;
   }
   
   @Column(name="tno_error_code")
   public String getTnoErrorCode() {
      return tnoErrorCode;
   }

   public void setTnoErrorCode(String tnoErrorCode) {
      this.tnoErrorCode = tnoErrorCode;
   }

   @Column(name="tno_error_txt")
   public String getTnoErrorTxt() {
      return tnoErrorTxt;
   }

   public void setTnoErrorTxt(String tnoErrorTxt) {
      this.tnoErrorTxt = tnoErrorTxt;
   }
   
   @Temporal(TemporalType.TIMESTAMP)
   @Column(name = "tno_created_dttm")
   public Date getTnoCreatedDttm() {
      return tnoCreatedDttm;
   }

   public void setTnoCreatedDttm(Date tnoCreatedDttm) {
      this.tnoCreatedDttm = tnoCreatedDttm;
   }
}



In my piece of code, i am saving the NewTransaction table's object first so that i can get the id of it for the future use, while setting and saving the object of type TxnNetworkObject at later point of time.

when i try to save TxnNetworkObject , i get the below exception

Quote:
Caused by: java.sql.SQLIntegrityConstraintViolationException: ORA-02291: integrity constraint (V21_V21OR_OSM.FK_RC8R1Q46VCMOPFNUB1YGVL2BO) violated - parent key not found

at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:85)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:206)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:455)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:413)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:1034)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:194)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:953)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1222)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3387)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3468)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeUpdate(OraclePreparedStatementWrapper.java:1350)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:208)
... 15 more


I tried to find the solution and got the below link:

http://stackoverflow.com/questions/15332930/integrity-constraint-violated-just-when-i-commit-the-transaction

but in my database, i could not get the trigger to be used for the particular user for hibernate.
Could you guys please help me resolving this particular issue.

Thank you in advance,
Keshav.


Top
 Profile  
 
 Post subject: Re: Getting error while saving a list object
PostPosted: Mon Aug 01, 2016 12:06 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
You need to add your data access code because that's where your error resides.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.