1
1
/*
2
- * Copyright 2002-2012 the original author or authors.
2
+ * Copyright 2002-2014 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
16
16
17
17
package org .springframework .orm .jpa .vendor ;
18
18
19
+ import java .lang .reflect .Method ;
19
20
import javax .persistence .EntityManagerFactory ;
20
21
21
22
import org .hibernate .SessionFactory ;
22
- import org .hibernate .ejb .HibernateEntityManagerFactory ;
23
23
24
24
import org .springframework .beans .factory .FactoryBean ;
25
25
import org .springframework .orm .jpa .EntityManagerFactoryAccessor ;
26
26
import org .springframework .util .Assert ;
27
+ import org .springframework .util .ReflectionUtils ;
27
28
28
29
/**
29
30
* Simple {@code FactoryBean} that exposes the underlying {@link SessionFactory}
@@ -42,8 +43,14 @@ public class HibernateJpaSessionFactoryBean extends EntityManagerFactoryAccessor
42
43
@ Override
43
44
public SessionFactory getObject () {
44
45
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
+ }
47
54
}
48
55
49
56
@ Override
0 commit comments