Issue Details (XML | Word | Printable)

Key: SPR-1547
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Juergen Hoeller
Reporter: David Sissoko
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Spring Framework

hibernate schema export is not called properly in close method of org.springframework.orm.hibernate3.LocalSessionFactoryBean

Created: 19/Dec/05 02:20 PM   Updated: 22/Dec/05 02:31 AM
Component/s: SpringDA
Affects Version/s: 1.2.6
Fix Version/s: 2.0 M1

Time Tracking:
Not Specified

Environment: windows XP

Virtual Machine: Sun JVM - 1.4.2


 Description  « Hide
I try to setup junit test with spring 1.2.6 and hibernate 3.05.
When the test ends up, it should drop the whole schema because hbm2ddl.auto=create-drop is set
The schema is created at applicationContext creation in the setup method.
The schema should be deleted at applicationContext closing but instead it throws an exception:

2005-12-19 19:18:33,054 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - <Retrieving dependent beans for bean 'userDao'>
2005-12-19 19:18:33,054 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - <Invoking destroy() on bean with name 'sessionFactory'>
2005-12-19 19:18:33,054 INFO [org.springframework.orm.hibernate3.LocalSessionFactoryBean] - <Closing Hibernate SessionFactory>
2005-12-19 19:18:33,054 INFO [org.hibernate.impl.SessionFactoryImpl] - <closing>
2005-12-19 19:18:33,054 INFO [org.hibernate.tool.hbm2ddl.SchemaExport] - <Running hbm2ddl schema export>
2005-12-19 19:18:33,054 INFO [org.hibernate.tool.hbm2ddl.SchemaExport] - <exporting generated schema to database>
2005-12-19 19:18:33,054 INFO [org.hibernate.connection.ConnectionProviderFactory] - <Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider>
2005-12-19 19:18:33,054 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] - <schema export unsuccessful>
org.hibernate.HibernateException: No local DataSource found for configuration - dataSource property must be set on LocalSessionFactoryBean
at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.configure(LocalDataSourceConnectionProvider.java:48)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:80)
at org.hibernate.tool.hbm2ddl.SchemaExport$ProviderConnectionHelper.getConnection(SchemaExport.java:431)
at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:130)
at org.hibernate.tool.hbm2ddl.SchemaExport.drop(SchemaExport.java:108)
at org.hibernate.impl.SessionFactoryImpl.close(SessionFactoryImpl.java:812)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean$TransactionAwareInvocationHandler.invoke(LocalSessionFactoryBean.java:1021)
at $Proxy0.close(Unknown Source)

It seems that sessionfactory is closed before Running hbm2ddl schema export. So when schema export executes, no datasource is available.



 All   Comments   Work Log   Change History   FishEye   Builds      Sort Order: Ascending order - Click to sort in descending order
Juergen Hoeller added a comment - 22/Dec/05 02:31 AM
Unfortunately, Hibernate reinstantiates a ConnectionProvider if it performs a schema export on "SessionFactory.close()". If you're using a Spring-provided DataSource, this means that LocalSessionFactoryBean needs to reexpose its DataSource to Hibernate. I've addressed this through special exposure in LocalSessionFactoryBean's "destroy()" implementation.

Juergen