wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes onetoone unidirectional relationship problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "onetoone unidirectional relationship problem" Watch "onetoone unidirectional relationship problem" New topic
Author

onetoone unidirectional relationship problem

Prasad Shindikar
Ranch Hand

Joined: Feb 18, 2007
Posts: 114
Hi,

I have created a very simple example depicting one to one unidirectional relationship mapping. However whenever I try to persist the information, I am getting the following Exception.

--
Exception in thread "main" javax.persistence.RollbackException: Error while commiting the transaction
at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:71)
at test.OneToOneTest.main(OneToOneTest.java:31)
Caused by: org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:54)
... 1 more
Caused by: java.sql.BatchUpdateException: Batch entry 0 insert into ORDERS (ORDER_DESC, ORDER_ID) values (myorder, 23) was aborted. Call getNextException to see the cause.
at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2537)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1328)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:351)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2674)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
... 9 more
--
I am using the following for development.

Eclipse Europa 3.3.2
JPA - Hibernate
Java 1.5

If required i will also send in the code!
Prasad Shindikar
Ranch Hand

Joined: Feb 18, 2007
Posts: 114
Please ignore the earlier post
Displaying below the complete, correct error stack and the respective files.

Hi,

I have created a very simple example depicting one to one unidirectional relationship mapping. However whenever I try to persist the information, I am getting the following Exception.

--
javax.persistence.RollbackException: Error while commiting the transaction
at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:71)
at simple.client.StudentManager.main(StudentManager.java:86)
Caused by: org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:54)
... 1 more
Caused by: java.sql.BatchUpdateException: Batch entry 0 insert into User (email, USER_BILLING_ID, userId) values (abc@xyz.com, 25, 24) was aborted. Call getNextException to see the cause.
at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2537)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1328)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:351)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2674)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
... 9 more

--
I am using the following for development.

Eclipse Europa 3.3.2
JPA - Hibernate
Java 1.5

The files:
--
BillingInfo.java

@Entity
public class BillingInfo implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="BILLING_ID")
private Long billingId;
private String creditCardType;
private String creditCardNumber;

public BillingInfo() {}

public Long getBillingId() {
return billingId;
}

public void setBillingId(Long billingId) {
this.billingId = billingId;
}

public String getCreditCardType() {
return creditCardType;
}

public void setCreditCardType(String creditCardType) {
this.creditCardType = creditCardType;
}

public String getCreditCardNumber() {
return creditCardNumber;
}

public void setCreditCardNumber(String creditCardNumber) {
this.creditCardNumber = creditCardNumber;
}
}
--

--
User.java

@Entity
public class User implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long userId;
private String email;
@OneToOne(cascade=CascadeType.ALL)
@JoinColumn(name = "USER_BILLING_ID", referencedColumnName = "BILLING_ID",
updatable = false)
private BillingInfo billingInfo;
//since the reference of BillingInfo is available in User and the reference of User is not
//available in BillingInfo, this is a type of Unidirectional Relationship

public User() {}



public Long getUserId() {
return userId;
}

public void setUserId(Long userId) {
this.userId = userId;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public BillingInfo getBillingInfo() {
return billingInfo;
}

public void setBillingInfo(BillingInfo billingInfo) {
this.billingInfo = billingInfo;
}
}
--

--
a simple client

public static void main(String [] args){
EntityTransaction et = em.getTransaction();
try{
User user = new User();
BillingInfo bill = new BillingInfo();
bill.setCreditCardType("VISA");
bill.setCreditCardNumber("123456789");
user.setBillingInfo(bill);
user.setEmail("abc@xyz.com");
et.begin();
em.persist(user);
et.commit();
} catch(Exception e) {
e.printStackTrace();
} finally {
em.close();
emf.close();
}

}
--
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: onetoone unidirectional relationship problem
 
Similar Threads
Persisting second identical object causes ConstraintViolationException?
Perf Tests failing badly on mysql
insert proble postgrest
Hell with postgres + hibernate
How to remove and insert entity in same transaction?