3 回答

largeQ
TA貢獻2039條經驗 獲得超8個贊
偉大的工作安德里亞斯。我創建了一個Bean版本,以便可以自動裝配SessionFactory。
import javax.persistence.EntityManagerFactory;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
....
@Autowired
private EntityManagerFactory entityManagerFactory;
@Bean
public SessionFactory getSessionFactory() {
if (entityManagerFactory.unwrap(SessionFactory.class) == null) {
throw new NullPointerException("factory is not a hibernate factory");
}
return entityManagerFactory.unwrap(SessionFactory.class);
}
添加回答
舉報
0/150
提交
取消