sessionfactory

NHibernate SessionFactory Thread safe Issue

早过忘川 提交于 2019-12-05 12:33:39
So here is the problem. I have a common class library that holds all the repositories, domain and mapping files so the library can be reused within other web beased applications. Now within this class library there is a peiece of code that allows itself to create a session factory to be used in its repositories. Code looks something like this. private static ISessionFactory sessionFactory; private static Configuration configuration; public static Configuration Configuration() { if (configuration == null) { configuration = new Configuration().Configure(); } return configuration; } private

Spring + Hibernate + JPA: How to reload EntityManagerFactory at runtime

一世执手 提交于 2019-12-05 12:32:56
I have been searching for this the last few hours maybe some of you can help me. I try to achieve a reload of my mapping info in EntityManagerFactory (or SessionFactory) at runtime in spring The EntityManagerFactory is defined as follows: <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="persistenceXmlLocation" value="persistence.xml" /> <property name="persistenceUnitName" value="JPAService" /> <property name="persistenceProviderClass" value="org.hibernate.ejb.HibernatePersistence"/> <property name="dataSource" ref=

How do I access Hibernate statistics from an entitymanager?

♀尐吖头ヾ 提交于 2019-12-05 03:28:37
问题 I'm using Spring 3.1.1.RELEASE, JUnit 4.8.1, and Hibernate 4.1.5.Final. I'm trying to test whether my second level cache is configured correctly, but am unsure of how to do it. I'm using the JPA entity manager, configured in Spring like so ... <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="jpaDialect"> <bean class="org.collegeboard.springboard.core.jpa.HibernateJpaDialect"> <property name="flushMode" value="COMMIT"/>

how does hibernate sessionfactory manage session?

。_饼干妹妹 提交于 2019-12-05 00:49:19
问题 I have just got the relationship between Hibernate Session and Connection. But now, I get another question: how does hibernate sessionfactory manage session? In the following code segment: save() method of a DAO class: Session session = sessionFactory.openSession(); Transaction tx=null; tx=session.beginTransaction(); session.save(transientInstance); session.flush(); tx.commit(); When we call sessionFactory.openSession() , it will create a new session attached to the current thread (through

java.lang.IllegalArgumentException: expecting IdClass mapping

家住魔仙堡 提交于 2019-12-04 22:25:06
I have configured composite primary key for my entity Employee as follows Employee.java: @Entity @Table(name="employee") @Proxy(lazy=false) @IdClass(EmployeeId.class) public class Employee implements Serializable { private static final long serialVersionUID = 1L; private EmployeeId employeeId; private Person person; private Branch branch; private boolean isActive; public Employee() { } @EmbeddedId @AttributeOverrides({ @AttributeOverride(name="person", column = @Column(name="person_id")), @AttributeOverride(name="branch", column = @Column(name="branch_id"))}) public EmployeeId getEmployeeId()

Hibernate opening/closing session, the correct approach for DAO

拥有回忆 提交于 2019-12-04 12:08:40
I have written this Hibernate object DAO, however with this approach, it is using session per update approach (which I don't think it's right). The reason why I don't think its right because I am running into problems with my User class, which contains collections that are lazily fetched. Since when retrieving each User from the DAO, the session is closed. Therefore I cannot get my collections. From time to time, it is also doing a lot of unnecessary updates to the table because the object is detached. So are there any ways of fixing my DAO, like using getCurrentSession() ? import java.util

What pooled data source should I use for Spring 3.1.0, Hibernate 4.0.1.Final, and MySQL 5.1?

旧巷老猫 提交于 2019-12-04 05:28:17
I'm using Spring 3.1.0.RELEASE, Hibernate 4.0.1.Final, and MySQL 5.1. What is the pooled data source I should be using? I'm currently using (snippet from application context file) ... <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName"> <value>com.mysql.jdbc.Driver</value> </property> <property name="url"> <value>jdbc:mysql://localhost:3306/myproj</value> </property> <property name="username"> <value>myproj</value> </property> <property name="password"> <value>password</value> </property> </bean> but this isn't a pooled

getting hibernate default schema name programmatically from session factory?

旧时模样 提交于 2019-12-03 16:41:01
问题 I was wondering if there is a way to get the default schema name from session factory, somehow? The reason I need to get it is because I have to use a one native SQL and I have multiple session factories for multiple schemas and a single data source. All the generated hibernate queries are being ran by a single user which has select access to other schemas. 回答1: I just found out that hibernate has {h-schema} replacement that can be used in native sql queries. So this does the job cleanly when

NHibernate & WCF: Performance (session reuse) vs. concurrency (simultaneous requests)

跟風遠走 提交于 2019-12-03 16:00:13
We are working on different integrations to a swarm of identically structured legacy databases that basically cannot be altered. For this, we added an auxiliary database for holding things like meta-information, routing rules and for temporarily holding data for the legacy databases. We are mainly using NHibernate to connect to the databases. One application is a WCF Service that needs to inserts incoming data into nested tables that are really wide (dozens of columns). Obviously, performance is an issue, so I have been looking to be as economic as possible with the NHibernate transactions. At

In Grails how do I access the hibernate session inside of a domain class static method?

限于喜欢 提交于 2019-12-03 07:38:00
问题 I've read various articles on the web, but they seem rather scattered on this point. Exactly what do I need to do in my configuration and in my method to get the hibernate session. I'm trying to make some direct sql calls for stored procedures. I have a large code base that I am porting from Ruby with lots of static methods and stored procedure calls. If I need to use the sessionFactory, then how to I get access to it? 回答1: From a static method you can pull the sessionFactory bean from the