Skip to content

Commit bf5739c

Browse files
committed
HibernateJpaSessionFactoryBean is compatible with Hibernate 4.3 as well now
Issue: SPR-12401
1 parent 5aefcc8 commit bf5739c

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaSessionFactoryBean.java

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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.
@@ -16,14 +16,15 @@
1616

1717
package org.springframework.orm.jpa.vendor;
1818

19+
import java.lang.reflect.Method;
1920
import javax.persistence.EntityManagerFactory;
2021

2122
import org.hibernate.SessionFactory;
22-
import org.hibernate.ejb.HibernateEntityManagerFactory;
2323

2424
import org.springframework.beans.factory.FactoryBean;
2525
import org.springframework.orm.jpa.EntityManagerFactoryAccessor;
2626
import 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

Comments
 (0)