11/* 
2-  * Copyright 2002-2012  the original author or authors. 
2+  * Copyright 2002-2014  the original author or authors. 
33 * 
44 * Licensed under the Apache License, Version 2.0 (the "License"); 
55 * you may not use this file except in compliance with the License. 
1616
1717package  org .springframework .orm .jpa .vendor ;
1818
19+ import  java .lang .reflect .Method ;
1920import  javax .persistence .EntityManagerFactory ;
2021
2122import  org .hibernate .SessionFactory ;
22- import  org .hibernate .ejb .HibernateEntityManagerFactory ;
2323
2424import  org .springframework .beans .factory .FactoryBean ;
2525import  org .springframework .orm .jpa .EntityManagerFactoryAccessor ;
2626import  org .springframework .util .Assert ;
27+ import  org .springframework .util .ReflectionUtils ;
2728
2829/** 
2930 * Simple {@code FactoryBean} that exposes the underlying {@link SessionFactory} 
@@ -42,8 +43,14 @@ public class HibernateJpaSessionFactoryBean extends EntityManagerFactoryAccessor
4243	@ Override 
4344	public  SessionFactory  getObject () {
4445		EntityManagerFactory  emf  = getEntityManagerFactory ();
45- 		Assert .isInstanceOf (HibernateEntityManagerFactory .class , emf );
46- 		return  ((HibernateEntityManagerFactory ) emf ).getSessionFactory ();
46+ 		Assert .state (emf  != null , "EntityManagerFactory must not be null" );
47+ 		try  {
48+ 			Method  getSessionFactory  = emf .getClass ().getMethod ("getSessionFactory" );
49+ 			return  (SessionFactory ) ReflectionUtils .invokeMethod (getSessionFactory , emf );
50+ 		}
51+ 		catch  (NoSuchMethodException  ex ) {
52+ 			throw  new  IllegalStateException ("No compatible Hibernate EntityManagerFactory found: "  + ex );
53+ 		}
4754	}
4855
4956	@ Override 
0 commit comments