Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 3.1
Spring Framework version: 1.2.5
Below is an excerpt of the Spring Context file I am using to initialize my Hibernate environment.
Code:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="mappingResources">
<list>
<value>ca/gc/rcmp/nsor/domain/hibernate/Victim.hbm.xml</value>
</list>
</property>
<!-- extra content omitted -->
</bean>
I am trying out the code below
Code:
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.hibernate.cfg.Configuration;
import org.springframework.orm.hibernate3.LocalSessionFactoryBean;
// Code excerpt below excludes class definition and constructors.
ApplicationContext ctx =
new FileSystemXmlApplicationContext(APP_CONTEXT_FILENAME)
LocalSessionFactoryBean lsfb = (LocalSessionFactoryBean)
ctx.getBean("sessionFactory");
Configuration cfg = lsfb.getConfiguration();
The cast to LocalSessionFactoryBean throws a ClassCastException
Code:
Exception in thread "main" java.lang.ClassCastException: $Proxy0
at ca.gc.rcmp.nsor.util.Remove.main(MyClass.java:36)
How do I get a reference to the LocalSessionFactoryBean as defined in the SpringContext file?
Is there another way of the getting the org.hibernate.cfg.Configuration given a SessionFactory?
Thanks.
Josh.