-->
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: Event Listeners (or Interceptor) with non-entity?
PostPosted: Tue Sep 13, 2005 3:57 pm 
Newbie

Joined: Thu Jul 01, 2004 9:09 am
Posts: 16
Location: USA
Hibernate version: 3.0.5

Mapping documents:

(Snippet):

Code:
      <bag name="preferredVendors" table="VENDOR_CLN" order-by="PK_VENDOR_ID" lazy="false">
          <key column="PK_CLN_ID"/>
          <composite-element class="LinkedVendor">
              <property name="auditUser" column="AUDIT_USER"/>
              <many-to-one column="PK_VENDOR_ID" name="vendor" class="Vendor" lazy="false"/>
          </composite-element>
      </bag>


Full stack trace of any exception that occurs:

Code:
10422 [main] DEBUG org.hibernate.util.JDBCExceptionReporter  - Could not execute JDBC batch update [insert into VENDOR_CLN (PK_CLN_ID, AUDIT_USER, PK_VENDOR_ID) values (?, ?, ?)]
java.sql.BatchUpdateException: ORA-01400: cannot insert NULL into ("SCHEMA"."AUDIT_ROW"."USER_NAME")
ORA-06512: at "SCHEMA.AUDIT_TRAIL", line 18
ORA-06512: at "SCHEMA.VENDOR_CLN_BI0", line 16
ORA-04088: error during execution of trigger 'SCHEMA.VENDOR_CLN_BI0'

   at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:459)
   at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:3907)
   at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:174)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
   at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324)
   at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
   at com.xifin.lor.dao.hibernate.HibernateClientDao$1.doInHibernate(HibernateClientDao.java:75)
   at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:315)
   at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:288)
   at com.xifin.lor.dao.hibernate.HibernateClientDao.updatePreferences(HibernateClientDao.java:54)
   at com.xifin.lor.dao.PortableClientDaoTester.testUpdateAssociations_CreatePreferredVendor(PortableClientDaoTester.java:84)
   at com.xifin.lor.dao.hibernate.HibernateClientDaoTest.testUpdateAssociations_CreatePreferredVendor(HibernateClientDaoTest.java:53)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:324)
   at junit.framework.TestCase.runTest(TestCase.java:154)
   at junit.framework.TestCase.runBare(TestCase.java:127)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:118)
   at junit.framework.TestSuite.runTest(TestSuite.java:208)
   at junit.framework.TestSuite.run(TestSuite.java:203)
   at junit.textui.TestRunner.doRun(TestRunner.java:116)
   at com.intellij.rt.execution.junit2.IdeaJUnitAgent.doRun(IdeaJUnitAgent.java:57)
   at junit.textui.TestRunner.start(TestRunner.java:172)
   at com.intellij.rt.execution.junit.TextTestRunner2.startRunnerWithArgs(TextTestRunner2.java:23)
   at com.intellij.rt.execution.junit2.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:97)
   at com.intellij.rt.execution.junit2.JUnitStarter.main(JUnitStarter.java:31)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:324)
   at com.intellij.rt.execution.application.AppMain.main(AppMain.java:86)

Name and version of the database you are using: Oracle 9i

The generated SQL (show_sql=true):

insert into VENDOR_CLN (PK_CLN_ID, AUDIT_USER, PK_VENDOR_ID) values (?, ?, ?)

Description

I have a legacy database. It has a table named VENDOR_CLN which is an association table between CLN (which can have a number of linked vendors) and VENDOR.

The association table itself has an AUDIT_USER field. I followed the advice in the FAQ for this situation as you see above and am using a <composite-element>. The AUDIT_USER field of the association table needs to be populate during inserts/updates (it has a non-null constraint as you can see from the above stacktrace).

I was hoping to use an Event Listener or Interceptor to fill-in the AUDIT_USER field much like in the Auditable example in the hibernate manual (see I did some reading before bothering you guys!).

My listeners and/or interceptor never fires when this item is inserted however. I think the problem is that this association table is not an "entity" (it is a <composite-element>) and apparently event/interceptor stuff only works for entities. Note that I *do* see the listeners firing for various entities, so I'm pretty sure I've configured the listeners properly.

So here's my question: What will my mapping look like for a one-to-many association table that contains a field that must be updated in a event listener (or interceptor)?


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.