Announcement Announcement Module
Collapse
No announcement yet.
onPrepareStatement called twice on batch update statements Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    Any Idea about this anyone ?

    Comment

    Working...
    X