-->
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: Create new entity in Pre/PostUpdateListener
PostPosted: Tue Mar 06, 2007 8:23 am 
Newbie

Joined: Tue Mar 06, 2007 8:13 am
Posts: 2
Is it possible to create new entity in Pre or PostUpdateListener? I see that my listener is being called, but creating entity has no effect on database.

Example

class MyListener implements PreUpdateListener
{
public boolean onPreUpdate(PreUpdateEvent event)
{
if (event.getEntity() instanceof Dog == false)
return false;

LogEntry e = new LogEntry();
e.setText("Entity of class " + event.getEntity.getClass() + " updated.");

event.getPersister().getFactory().getCurrentSession().persist(e);

return false;
}
}

So when any Dog is updated new log entry should be created. But it doesn't work this way - log entry isn't persisted, although no exception is thrown. Is it forbidden to create new entities in pre/post update listeners?

// Edit:

sorry for double post, network problems :/


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 07, 2008 2:01 pm 
Newbie

Joined: Thu Nov 02, 2006 8:26 pm
Posts: 6
Try:

StatelessSession session = HibernateUtil.getSessionFactory().openStatelessSession();
session.beginTransaction();
session.insert(myEntity);
session.getTransaction().commit();
session.close();


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.