Results 1 to 2 of 2

Thread: onPrepareStatement called twice on batch update statements

  1. #1
    Join Date
    Jun 2009
    Posts
    2

    Default onPrepareStatement called twice on batch update statements

    Hi All,

    I have 2 questions.

    1) I've been playing with hibernate interceptors and I noticed that on batch statements the interceptor's onPrepareStatement gets called twice! Is this the normal behavior? If I want to register such an event only once what is the best way to do it (given a multi-threaded environment)?

    2) While writing unit tests, I am extending AbstractTransactionalJUnit4SpringContextTests so as to not dirty my database with my tests, the events are fired upon session flush and issuing a roll back seems to exclude some events (mainly onCollectionUpdate for entities that didn't exist before). I tried using an in memory database and running setup scripts at the beginning but I assume this will be a PITA when the schema gets more and more complicated. Is there any other way to do this ?

    I am using an EmptyInterceptor implementation that implements all onXXX methods this way:

    Code:
    public String onPrepareStatement(String sql) {
    	log.trace("onPrepareStatement statement:\n"+sql);
    	return super.onPrepareStatement(sql);
    }
    the interceptor is attached to the session factory as follows:

    Code:
    <bean id="sessionFactory"
    		class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
    		<property name="dataSource" ref="dataSource"/>
    		<property name="mappingResources">
    			<list>
    				...
    			</list>
    		</property>
    		<property name="hibernateProperties">
    			<props>
    				<prop key="hibernate.show_sql">true</prop>			
    			</props>
    		</property>		
    		<property name="entityInterceptor">
    			<bean class="com.mycompany.play.EmptyLoggingInterceptor"/>
    		</property>
    	</bean>

  2. #2
    Join Date
    Jun 2009
    Posts
    2

    Default

    Any Idea about this anyone ?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •