-->
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: Problems with using Pre*EventListener and SQLQuery
PostPosted: Thu Jun 05, 2008 10:45 am 
Newbie

Joined: Thu Jun 05, 2008 9:47 am
Posts: 2
Good time.

I have some problems with using Pre*EventListener and SQLQuery.

Problem 1 :

If in the PreUpdateEventListener create insert into db usage SQLQuery, hibbernate generate exception.

Table nodeproperty_annotation_history don`t have mapping, and using only through JDBC(please see "Code")

1.1 Code

@Transactional
public Oblect createCommand(){

.....
hibernateSupport.saveOrUpdate(command);
.....

}


......

public boolean onPreUpdate(PreUpdateEvent p_event) {

String sql ="INSERT INTO nodeproperty_annotation_history( value, size, command_id) VALUES( 'testValue', 0, 0)";

SQLQuery query = hibernateSupport.getHibernateSession().createSQLQuery(sql);
query.executeUpdate();

return false;
}

1.2 Exception

exception: java.lang.IndexOutOfBoundsException: Index: 1, Size: 0
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.get(ArrayList.java:322)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:41)
at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:969)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1114)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at com.spinbitz.commons.utils.HibernateSupportImpl.find(HibernateSupportImpl.java:63)
at com.spinbitz.commons.utils.HibernateSupportImpl.findSingle(HibernateSupportImpl.java:70)

........


Problem 2.

After hibernate create this exception, hibernate rollback all objects, but all insert that created from SQLQuery does not delete.


I`m use
- himernate 3.2.6
- hibernate-annotation-3.3.1

Maybe who know, how fix this problem

Thank you!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2008 4:03 pm 
Newbie

Joined: Fri Sep 12, 2008 3:53 pm
Posts: 4
I had the same issue as you mentioned.

I solved it by setting flush mode to MANUAL and resetting it back to the original at the end while executing a call to the stored procedure.

Here is code :


Code:
public class MyEventListener implements PreUpdateEventListener, PostUpdateEventListener,
        PreInsertEventListener, PostInsertEventListener
{
......

  public boolean onPreUpdate(final PreUpdateEvent event) {
   ....
        final FlushMode flushMode = session.getFlushMode();
        // disable flush mode
        session.setFlushMode(FlushMode.MANUAL);

        session.executeNativeUpdate(
            new NativeSQLQuerySpecification("call MY_STORE_PROC( ? )", new NativeSQLQueryReturn[] {}, null),
            new QueryParameters(Hibernate.LONG, myid));

        // restore flush mode
        session.setFlushMode(flushMode);
  }

}



regards.


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.