-->
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.  [ 4 posts ] 
Author Message
 Post subject: onPreInsert veto and identity columns
PostPosted: Tue Oct 18, 2005 11:46 am 
Newbie

Joined: Mon Oct 17, 2005 3:42 pm
Posts: 17
I've got a PreInsertEventListener that in some cases 'vetos' the insert by returning true. This seems to work fine when my entity's id is mapped to a sequence, but when the id is mapped to an identity column, I get the following exception.

Code:
FULL STACK TRACE: org.hibernate.AssertionFailure: null identifier
   at org.hibernate.engine.EntityKey.<init>(EntityKey.java:33)
   at org.hibernate.engine.PersistenceContext.checkUniqueness(PersistenceContext.java:581)
   at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:243)
   at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:160)
   at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:95)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:96)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
   at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:468)
   at org.hibernate.engine.Cascades$5.cascade(Cascades.java:154)
   at org.hibernate.engine.Cascades.cascadeAssociation(Cascades.java:771)
   at org.hibernate.engine.Cascades.cascade(Cascades.java:720)
   at org.hibernate.engine.Cascades.cascade(Cascades.java:847)
   at org.hibernate.event.def.AbstractSaveEventListener.cascadeBeforeSave(AbstractSaveEventListener.java:332)
   at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:214)
   at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:160)
   at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:95)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:96)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
   at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:468)
   at org.hibernate.engine.Cascades$5.cascade(Cascades.java:154)
   at org.hibernate.engine.Cascades.cascadeAssociation(Cascades.java:771)
   at org.hibernate.engine.Cascades.cascade(Cascades.java:720)
   at org.hibernate.engine.Cascades.cascadeCollection(Cascades.java:895)
   at org.hibernate.engine.Cascades.cascadeAssociation(Cascades.java:792)
   at org.hibernate.engine.Cascades.cascade(Cascades.java:720)
   at org.hibernate.engine.Cascades.cascade(Cascades.java:847)
   at org.hibernate.event.def.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:363)
   at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:265)
   at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:160)
   at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:95)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:96)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
   at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:468)
   at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:463)
   at org.springframework.orm.hibernate3.HibernateTemplate$18.doInHibernate(HibernateTemplate.java:613)


This seems to be happening when hibernate tries to use the id that would have been pulled out of the inserted row, but can't because the row was never inserted.

The same listener seems to work as expected when the id is mapped to a sequence, but that is not an option for our production environment.

Is this a hibernate bug, an unsupported configuration, or am I misunderstanding something?

In researching this issue, I stumbled accross the Lifecycle interface and will give that a try as well.

thanks in advance,
danch
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 18, 2005 2:23 pm 
Newbie

Joined: Mon Oct 17, 2005 3:42 pm
Posts: 17
Update:
putting this behavior in my entities via Lifecycle seems to do the trick.

There are a couple of reasons I don't like this approach (the behavior I'm trying to implement is more of a cross-cutting concern and really isn't part of the entity, and the interception/event listening approach is just all-around cleaner in the implementation), so I'd still like to know if the behavior using the event listener is a bug or my misunderstanding.

Also, Lifecycle is in the (deprecated?) 'org.hibernate.classic' package, but gives no indication as to what it is superceded by in the Hibernate 3 api. Is it replaced by the Event subsystem?

Another thing I noticed about the Lifecycle interface in Hibernate 3 is that it takes the hibernate 3 version of Session as a parameter, not org.hibernate.classic.Session. I dunno, but this seems odd.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 18, 2005 3:01 pm 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
Does using an Interceptor instead of an EventListener not work?

_________________
nathan


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 18, 2005 3:15 pm 
Newbie

Joined: Mon Oct 17, 2005 3:42 pm
Posts: 17
The interceptor has no way to veto the insert (as far as I can tell)

That was my first approach. Implementing this facility has been a learning experience, for sure!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.