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.  [ 1 post ] 
Author Message
 Post subject: Getting ConstraintViolationException when attempting to inse
PostPosted: Mon Apr 23, 2007 1:14 pm 
Newbie

Joined: Mon Apr 23, 2007 12:14 pm
Posts: 1
Hello,

I am having a ConstraintViolationException when attempting to insert a list of transient object. I read through an XML file and builds a collection of objects that I wish to save later. The object is simple and very strait forward with no relation with any other table. The primary key is being generated by a UUID generator so I really don't see any duplicate.

I tried every options in my hand, including using a set rather than list. Printed out each object before saving to see their state, turned out hibernate sql statement for debug, notthing points me to a solution.

I also tried session.save(), or session.saveOrUpdate().

As you can see this is a fairly simple problem. Yet I can't find out whats wrong. Any help will be appreciated. Mapping file, and java code are given below.

Thanks,
Nemo



04/20 16:02:16,335 [MessageListenerThreadPool : 3] PublishingNovusDocMigration ERROR TargetServiceBean: HibernateException occurred when trying to flush session.
org.hibernate.exception.ConstraintViolationException: could not insert: [myObjHib]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:69)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java(Compiled Code))
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java(Compiled Code))
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java(Compiled Code))
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java(Inlined Compiled Code))
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java(Compiled Code))
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java(Compiled Code))
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java(Inlined Compiled Code))
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java(Inlined Compiled Code))
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java(Compiled Code))
at utilities.hibernate.HibernateUtilImpl.flushSession(HibernateUtilImpl.java(Compiled Code))
at services.target.ejb.TargetServiceBean.findTargetContent(TargetServiceBean.java(Compiled Code))
at services.target.ejb.TargetServiceBean.findTargetContent(TargetServiceBean.java(Inlined Compiled Code))
at services.target.ejb.EJSLocalStatelessTargetService_5e61c602.findTargetContent(Unknown Source)
at services.target.TargetServiceDelegate.findTargetContent(TargetServiceDelegate.java(Compiled Code))
at services.ServiceRequestDelegateImpl.process(ServiceRequestDelegateImpl.java:42)
at services.ejb.ServiceRequestDelegateBean.process(ServiceRequestDelegateBean.java:48)
at services.ejb.ServiceRequestDelegateBean.process(ServiceRequestDelegateBean.java:93)
at services.ejb.EJSLocalStatelessServiceRequestDelegate_8a8c7cb6.process(Unknown Source)
at services.ServiceRequestDelegateDelegate.process(ServiceRequestDelegateDelegate.java:62)
at services.ejb.AbstractServiceMDBean.processServiceRequest(AbstractServiceMDBean.java:421)
at services.ejb.ServiceMDBean.callService(ServiceMDBean.java:234)
at services.ejb.ServiceMDBean.onMessage(ServiceMDBean.java:203)
at com.ibm.ejs.jms.listener.MDBWrapper$PriviledgedOnMessage.run(MDBWrapper.java:211)
at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java(Compiled Code))
at com.ibm.ejs.jms.listener.MDBWrapper.callOnMessage(MDBWrapper.java:200)
at com.ibm.ejs.jms.listener.MDBWrapper.onMessage(MDBWrapper.java:178)
at com.ibm.mq.jms.MQSession.run(MQSession.java(Compiled Code))
at com.ibm.ejs.jms.JMSSessionHandle.run(JMSSessionHandle.java(Compiled Code))
at com.ibm.ejs.jms.listener.ServerSession.connectionConsumerOnMessage(ServerSession.java(Compiled Code))
at com.ibm.ejs.jms.listener.ServerSession.onMessage(ServerSession.java(Compiled Code))
at com.ibm.ejs.jms.listener.ServerSession.dispatch(ServerSession.java(Inlined Compiled Code))
at sun.reflect.GeneratedMethodAccessor82.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
at com.ibm.ejs.jms.listener.ServerSessionDispatcher.dispatch(ServerSessionDispatcher.java(Compiled Code))
at com.ibm.ejs.container.MDBWrapper.onMessage(MDBWrapper.java(Compiled Code))
at com.ibm.ejs.container.MDBWrapper.onMessage(MDBWrapper.java(Compiled Code))
at com.ibm.ejs.jms.listener.ServerSession.run(ServerSession.java(Compiled Code))
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java(Compiled Code))
Caused by: java.sql.BatchUpdateException: ORA-00001: unique constraint (CODES.PK_WLNV_MINED_NOD_LINK) violated

at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:459)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java(Compiled Code))
at com.ibm.ws.rsadapter.jdbc.WSJdbcStatement.pmiExecuteBatch(WSJdbcStatement.java(Compiled Code))
at com.ibm.ws.rsadapter.jdbc.WSJdbcStatement.executeBatch(WSJdbcStatement.java(Compiled Code))
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java(Compiled Code))
at org.hibernate.jdbc.BatchingBatcher.addToBatch(BatchingBatcher.java(Compiled Code))
... 52 more






Here is the mapping file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="x.y.z.hib">
<class mutable="true" name="x.y.z.hib.myObjHib" table="WLNV_MINED_NOD_LINK">
<meta attribute="scope-class">public</meta>
<meta attribute="implement-equals">true</meta>

<id name="uuid" column="UUID" type="x.y.z.utilities.hibernate.UuidUserType">
<meta attribute="property-type">x.y.z.utilities.Uuid</meta>
<meta attribute="use-in-tostring">true</meta>
<meta attribute="use-in-equals">true</meta>
<generator class="x.y.z.utilities.hibernate.UuidGenerator" />
</id>
<property name="jobId" column="JOB_ID" not-null="true" type="x.y.z.utilities.hibernate.UuidUserType">
<meta attribute="use-in-tostring">true</meta>
<meta attribute="use-in-equals">true</meta>
</property>

<property name="documentUuid" column="DOC_ID" not-null="true" type="x.y.z.utilities.hibernate.UuidUserType">

<meta attribute="use-in-tostring">true</meta>
<meta attribute="use-in-equals">true</meta>
</property>

<property name="blockUuid" column="BLOCK_UUID" not-null="true" type="x.y.z.utilities.hibernate.UuidUserType">
<meta attribute="use-in-tostring">true</meta>
<meta attribute="use-in-equals">true</meta>
</property>

<property name="blockMnem" column="BLOCK_MNEM" type="string" not-null="true">
<meta attribute="use-in-tostring">true</meta>
<meta attribute="use-in-equals">true</meta>
</property>

<property name="blockLabelDesignator" column="BLOCK_LABEL_DESIGNATOR" type="string">
<meta attribute="use-in-tostring">true</meta>
<meta attribute="use-in-equals">true</meta>
</property>

<property name="blockMnemOrder" column="BLOCK_MNEM_ORDER" type="integer" not-null="true">
<meta attribute="use-in-tostring">true</meta>
<meta attribute="use-in-equals">true</meta>
</property>

<property name="ksBlockLevel" column="KS_BLOCK_LEVEL" type="integer">
<meta attribute="use-in-tostring">true</meta>
<meta attribute="use-in-equals">true</meta>
</property>

<property name="runheadParaId" column="RUNHEAD_PARA_ID" type="string">
<meta attribute="use-in-tostring">true</meta>
<meta attribute="use-in-equals">true</meta>
</property>

<property name="nodBlockIndex" column="NOD_BLOCK_INDEX" type="integer" not-null="true">
<meta attribute="use-in-tostring">true</meta>
<meta attribute="use-in-equals">true</meta>
</property>
</class>
</hibernate-mapping>



private void startBlock(String blockUuid)
{
block = new myObjHib();
block.setJobId(getCodesContext().getJobid());
block.setDocumentUuid(docUuid);
block.setBlockUuid(Uuid.getInstance(blockUuid));
block.setNodBlockIndex(new Integer(nodBlockIndex));

...

// I set the other varialbes later, and add block to the java list blocks.
}



And, here is the java code that actually iterates through the list and save each object one at a time.


public void endDocument() throws SAXException
{
myObjHib h = null;

try
{
Session s = HIBERNATE_UTIL.getSession();


for (Iterator i = blocks.iterator(); i.hasNext();)
{
System.out.println(++counter);
h = (myObjHib) i.next();
s.save(h);
Log.debug("myObjHib: " + h + "\n");
}

s.flush();
}
catch (Exception e)
{
String msg = "my error message";
LOG.error(msg, e);
throw new RuntimeException(msg, e);
}

super.endDocument();
}


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

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.