|
From: <jue...@we...> - 2003-07-17 12:17:52
|
Everyone, I've clarified the stored procedure issue with Thomas today. The proc = did not see the inserted row because it did not take part in the = HibernateTransactionManager-driven transaction. The reason for this was = that our StoredProdedure template fetched its JDBC Connection via = dataSource.getConnection, creating a new one in any case. I've just = changed this to DataSourceUtils.getConnection(dataSource): Now it will = receive a thread-bound Connection when in a DataSourceTransactionManager = or HibernateTransactionManager transaction. I've already committed the = change. BTW, I've also reintroduced eager initialization of the = SQLExceptionTranslater used by JdbcTemplate, but now in = afterPropertiesSet instead of in setDataSource. The original motivation = for lazy init was to avoid unnecessary initialization of the default = translater on setDataSource if a translater is explicitly set via = setSQLExceptionTranslater anyway. Unfortunately, lazy init via = connection metadata after a SQLException got thrown seems to cause = problems with some JNDI connection pools resp. JTA implementations. A = user reported this on our SourceForge forums yesterday. So it is now = recommended to call afterPropertiesSet on JdbcTemplate creation (new in = 0.9.1), or set the SQLExceptionTranslater explictly (also in 0.9), to = avoid potentially erroneous behavior. Juergen -----Original Message----- From: j=FCrgen h=F6ller [werk3AT]=20 Sent: Tuesday, July 15, 2003 5:06 PM To: Achleitner Thomas; spr...@li... Subject: RE: [Springframework-user] Transactions: Hibernate and Jdbc mixed up Thomas, Probably you just need to flush the Hibernate Session immediately at the = end of your Hibernate code. You can do this manually in your = HibernateCallback implementation by calling "session.flush()" at the = end, or better set your HibernateTemplate's "forceFlush" property to = true. By default, a Hibernate transaction just flushes at the end of the = transaction. This enables a very "soft" rollback until very late, as = normally the database will not have received any SQL statements yet. The = Javadoc of HibernateTemplate's "setForceFlush" method talks about this a = bit. As your JDBC access code depends on the Hibernate commands actually sent = to the database, you'll need the forced flush in the middle of the = transaction. Juergen -----Original Message----- From: Achleitner Thomas [mailto:ac...@ec...] Sent: Tuesday, July 15, 2003 4:42 PM To: spr...@li... Subject: [Springframework-user] Transactions: Hibernate and Jdbc mixed up Hello! Consider following situation (in pseudo code): doInTransaction() insert row with id =3D 1 using Hibernate (sessionFactory) load row with id =3D 1 using Jdbc / StoredProcedure (dataSource) end Since the insert and the load statement are executed within one single transaction the load statement is expected to return the inserted row with id =3D 1. I am using spring 0.9 and this is not working for me. = What is wrong about my configuration? ... <bean id=3D"dataSource" class=3D"com.interface21.jndi.JndiObjectFactoryBean"> <property name=3D"jndiName"> <value>jdbc/lms</value> </property> </bean> <bean id=3D"sessionFactory" class=3D"com.interface21.orm.hibernate.LocalSessionFactoryBean"> </bean> <bean id=3D"transactionManager" =09 class=3D"com.interface21.orm.hibernate.HibernateTransactionManager"> <property name=3D"sessionFactory"> <ref bean=3D"sessionFactory"/> </property> <property name=3D"dataSource"> <ref bean=3D"dataSource"/> </property> </bean> ... The insert statement gets executed in a DAO where property sessionFactory is set. The load statement gets executed in a separate DAO where property dataSource is set. thomas ------------------------------------------------------- This SF.Net email sponsored by: Parasoft Error proof Web apps, automate testing & more. Download & eval WebKing and get a free book. www.parasoft.com/bulletproofapps1 _______________________________________________ Springframework-user mailing list Spr...@li... https://lists.sourceforge.net/lists/listinfo/springframework-user ------------------------------------------------------- This SF.Net email sponsored by: Parasoft Error proof Web apps, automate testing & more. Download & eval WebKing and get a free book. www.parasoft.com/bulletproofapps1 _______________________________________________ Springframework-user mailing list Spr...@li... https://lists.sourceforge.net/lists/listinfo/springframework-user |