-->
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: @OneToMany Create problem
PostPosted: Tue Feb 16, 2010 2:14 pm 
Newbie

Joined: Tue Feb 16, 2010 1:59 pm
Posts: 2
Hi,
I'm getting the following exception during persistence when i have @OneToMany mapping in my hibernate objects.
StackTrace

Caused by: org.springframework.dao.DataIntegrityViolationException: Could not execute JDBC batch update; SQL [insert into JOB_FREQUENCY_INFO (CREATED_BY, CREATED_ON, LAST_UPDATED_BY, LAST_UPDATED_ON, VERSION_NO, TYPE, VALUE, UUID) values (?, ?, ?, ?, ?, ?, ?, ?)]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:637)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:683)
at com.test.service.impl.DataAccessImpl.create(DataAccessImpl.java:71)
... 3 more
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:254)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
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:1001)
at org.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:390)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:407)
... 6 more
Caused by: java.sql.BatchUpdateException: ORA-01400: cannot insert NULL into ("SYS"."JOB_FREQUENCY_INFO"."JOB_ID")

at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:343)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10656)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeBatch(DelegatingPreparedStatement.java:231)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:247)
... 13 more

Hibernate Objects:

@Entity
@Table(name = "JOB_SCHEDULE_INFO")
public class JobSchedule
{
@Id
@GeneratedValue(generator = "uniqueId")
@GenericGenerator(name = "uniqueId", strategy = "com.test.persistence.UniqueIDGenerator")
@Type(type = "com.test.persistence.ApplianceUUID")
@Column(name = "UUID", nullable = false)
protected ApplianceUUID uuid;

@OneToMany(fetch = FetchType.EAGER, cascade = { javax.persistence.CascadeType.ALL })
@Cascade( { CascadeType.ALL })
@JoinColumn(name = "JOB_ID")
private Set<JobFrequency> jobFreqValue;

@Column(name = "STATUS", nullable = false)
private boolean status;

//Some other fields
//getters and setters
}

@Entity
@Table(name = "JOB_FREQUENCY_INFO")
public class JobFrequency
{

@Id
@GeneratedValue(generator = "uniqueId")
@GenericGenerator(name = "uniqueId", strategy = "com.test.persistence.UniqueIDGenerator")
@Type(type = "com.test.persistence.ApplianceUUID")
@Column(name = "UUID", nullable = false)
protected ApplianceUUID uuid;

@Column(name = "TYPE", nullable = false)
private String type;

@Column(name = "VALUE", nullable = false)
private String value;

@ManyToOne
@JoinColumn(name = "JOB_ID", nullable = false, updatable = false, insertable = false)
private JobSchedule job;

//Some other fields
//getters and setters
}

Any help is greatly appreciated.

Thanks
Rohit


Top
 Profile  
 
 Post subject: Re: @OneToMany Create problem
PostPosted: Tue Feb 16, 2010 3:27 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
You must make the @OneToMany relation an inverse relation. See http://docs.jboss.org/hibernate/stable/ ... child.html for an example explaining why. The example uses xml mappings files, but I think the counterpart to inverse="true" (xml) is mappedBy="..." (annotations). See http://docs.jboss.org/hibernate/stable/ ... ollections for some more information.


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.