-->
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: Many-to-One relationship gives Could not execute JDBC batch
PostPosted: Wed Aug 01, 2012 2:50 pm 
Newbie

Joined: Wed Aug 01, 2012 2:28 pm
Posts: 2
I have a RrCacheJobs record which is the parent to RrCachePagelists records. One Job is parent to many Pagelists. The id for RrCacheJobs and RrCachePagelists is assigned.
I am having trouble updating the RrCachePagelist record. I only want to update the pagelist record and I am not updating any attributes in the job at this time.

Here is an abbreviated RrCachePagelist.java file and .hbm.xml file:

RrCachePagelist.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Apr 26, 2011 10:21:28 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="com.rampageinc.hiber.cache.RrCachePagelist" table="rr_cache_pagelist">
<id name="id" column="id" type="java.lang.Integer">
<generator class="assigned">
</generator>
</id>
<many-to-one name="rrCacheJobs" column="job_id" not-null="true" lazy="false" class="com.rampageinc.hiber.cache.RrCacheJobs"/>
<property name="name" type="string">
<column name="name" not-null="true" />
</property>
<!-- <property name="jobId" type="java.lang.Integer">
<column name="job_id" />
</property> -->
</class>
</hibernate-mapping>

RrCachePagelist.java:

public class RrCachePagelist {
private Integer id;
private String name;
private Integer jobId;

private RrCacheJobs rrCacheJobs;

... with appropriate constructor, getters and setters


RrCacheJobs.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Jan 31, 2012 11:19:31 AM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="com.rampageinc.hiber.cache.RrCacheJobs" table="rr_cache_jobs">
<id name="id" column="id" type="java.lang.Integer">
<generator class="assigned">
</generator>
</id>
<set name="rrCachePagelists" lazy="false" inverse="false" cascade="all">
<key column="job_id"/>
<one-to-many class="com.rampageinc.hiber.cache.RrCachePagelist"/>
</set>
<property name="security" type="java.lang.String">
<column name="security" />
</property>
</class>
</hibernate-mapping>

RrCacheJobs.java:
public class RrCacheJobs implements java.io.Serializable {
private Integer id;
private String security;
private Set<RrCachePagelist> rrCachePagelists = new HashSet<RrCachePagelist>(0);
public RrCacheJobs() {
}
... With appropriate constructor, getters and setters

Here is the code which does the update:

Transaction tx = null;
Session session = InitCacheSessionFactory.getInstance().getCurrentSession();
try{
tx = session.beginTransaction();
RrCachePagelist nrec = null;

// Passing in values to update using a workCachePage object.
nrec.copyDataToUpdate(workCachePage);
session.save(nrec);
tx.commit();

} catch (HibernateException hex) {
logger.error("RRSetCacheData.updatePagelistRecords hex: {}",hex.toString());
hex.printStackTrace();
if ( tx != null && tx.isActive()) {
tx.rollback();
}
throw new HiberCacheException (hex.getMessage());
} finally{
if (session != null && session.isOpen()) {
session.flush();
session.close();
}
}

copyDataToUpdate(workCachePage){
if ((workCachePage.getPageId() == null) && nrec.getId() != null){
nrec.setId(nrec.getId());
} else {
nrec.setId(workCachePage.getPageId());
}
}

Here is the stack trace:

org.hibernate.exception.DataException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:102)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:268)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:185)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:32
1)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)
at com.rampageinc.hiber.cache.impl.RRSetCacheData.updatePagelistRecords(RRSetCacheData.java:1323)

Caused by: java.sql.BatchUpdateException: data exception: string data, right truncation
at org.hsqldb.jdbc.JDBCPreparedStatement.executeBatch(Unknown Source)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
... 22 more


Top
 Profile  
 
 Post subject: Re: Many-to-One relationship gives Could not execute JDBC batch
PostPosted: Thu Aug 02, 2012 9:55 am 
Newbie

Joined: Wed Aug 01, 2012 2:28 pm
Posts: 2
The problem resided in the copyDataToUpdate(workCachePage) method.
1. I had been incorrectly trying to save data of the wrong type.
2. I did not need to explicitly set the RrCachePagelist.setJobId() nor did I need to explicitly set the RrCachePagelist.setRrCacheJobs().


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.