sessionfactory

Ensure NHibernate SessionFactory is only created once

假如想象 提交于 2019-11-27 13:40:57
I have written an NHibernateSessionFactory class which holds a static Nhibernate ISessionFactory. This is used to make sure we only have one session factory, and the first time OpenSession() is called I create the actuall SessionFactory - next times I use the same and open a session on it. The code looks like this: public class NhibernateSessionFactory : INhibernateSessionFactory { private static ISessionFactory _sessionFactory; public ISession OpenSession() { if (_sessionFactory == null) { var cfg = Fluently.Configure(). Database(SQLiteConfiguration.Standard.ShowSql().UsingFile("Foo.db")).

How can I set Datasource when I'm creating Hibernate SessionFactory?

点点圈 提交于 2019-11-27 12:27:06
I'm creating SessionFactory and I have my datasource as object in code where I'm creating SessionFactory, but i cannot set datasource to Hibernate Configuration object. So how can I set my datasource to my SessionFactory? Configuration configuration = new Configuration(); Properties properties = new Properties(); properties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLInnoDBDialect"); configuration.setProperties(properties); configuration.setProperty("packagesToScan", "com.my.app"); SessionFactory sessionFactory = configuration.configure().buildSessionFactory(); Dipesh Rathod

Hibernate SessionFactory vs. EntityManagerFactory

青春壹個敷衍的年華 提交于 2019-11-27 02:21:05
I am new to Hibernate and am unclear of whether to use a SessionFactory or EntityManagerFactory to obtain the hibernate session. What is the difference between the two? Pros & Cons? Prefer EntityManagerFactory and EntityManager . They are defined by the JPA standard. SessionFactory and Session are hibernate-specific. The EntityManager invokes the hibernate session under the hood. And if you need some specific features that are not available in the EntityManager , you can obtain the session by calling: Session session = entityManager.unwrap(Session.class); toytoy I want to add on this that you

Spring and hibernate: No Session found for current thread

故事扮演 提交于 2019-11-26 22:33:12
im gettting the following error org.hibernate.HibernateException: No Session found for current thread at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:97) at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1024) at com.fexco.shoptaxfreemobile.service.ProfileService.registerVisitor(ProfileService.java:57) at com.fexco.shoptaxfreemobile.controller.ProfileController.registerVisitor(ProfileController.java:91) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl

Looking for a not-deprecated session-factory

元气小坏坏 提交于 2019-11-26 21:40:02
问题 I am dealing with hibernate and as I opened my current project I figured out my Session-Factory is deprecated: AnnotationConfiguration af = new AnnotationConfiguration(); SessionFactory factory = af.configure().buildSessionFactory(); Session session = factory.openSession(); AnnotationConfiguration seems to be deprecated by now... So I checked the JavaDoc and I got told it moved to: org.hibernate.cfg.Configuration My code works fine so far, actually I don't want to change it... But I googled

How can I set Datasource when I'm creating Hibernate SessionFactory?

心不动则不痛 提交于 2019-11-26 18:11:57
问题 I'm creating SessionFactory and I have my datasource as object in code where I'm creating SessionFactory, but i cannot set datasource to Hibernate Configuration object. So how can I set my datasource to my SessionFactory? Configuration configuration = new Configuration(); Properties properties = new Properties(); properties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLInnoDBDialect"); configuration.setProperties(properties); configuration.setProperty("packagesToScan", "com.my

Ensure NHibernate SessionFactory is only created once

孤者浪人 提交于 2019-11-26 16:17:03
问题 I have written an NHibernateSessionFactory class which holds a static Nhibernate ISessionFactory. This is used to make sure we only have one session factory, and the first time OpenSession() is called I create the actuall SessionFactory - next times I use the same and open a session on it. The code looks like this: public class NhibernateSessionFactory : INhibernateSessionFactory { private static ISessionFactory _sessionFactory; public ISession OpenSession() { if (_sessionFactory == null) {

Spring and hibernate: No Session found for current thread

元气小坏坏 提交于 2019-11-26 08:22:55
问题 im gettting the following error org.hibernate.HibernateException: No Session found for current thread at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:97) at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1024) at com.fexco.shoptaxfreemobile.service.ProfileService.registerVisitor(ProfileService.java:57) at com.fexco.shoptaxfreemobile.controller.ProfileController.registerVisitor(ProfileController.java:91)