Questions tagged [sessionfactory]

A main interface used by the application to obtain a Hibernate session.

A main interface used by the application to obtain a Hibernate session. Hibernate requires to provide it with the configuration information required to connect to each database being used by an application as well as which classes are mapped to a given database. Each one of these database-specific configuration files, along with the associated class mappings, are compiled and cached by the SessionFactory, which is used to obtain Hibernate sessions. The SessionFactory is a heavyweight object that should ideally be created only once (since it's an expensive and slow operation) and threads servicing client requests obtain Session instances from this factory. Initially the SessionFactory should made available to the application that needs to perform persistence operations.

424 questions
269
votes
8 answers

Hibernate SessionFactory vs. JPA EntityManagerFactory

I am new to Hibernate and I'm not sure whether to use a Hibernate SessionFactory or a JPA EntityManagerFactory to create a Hibernate Session. What is the difference between these two? What are the pros & cons of using each of those?
elpisu
  • 2,695
  • 3
  • 13
  • 4
25
votes
7 answers

java.lang.IllegalArgumentException: expecting IdClass mapping

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…
Achaius
  • 5,326
  • 16
  • 59
  • 107
25
votes
6 answers

Spring and hibernate: No Session found for current thread

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…
Hip Hip Array
  • 4,425
  • 9
  • 45
  • 70
21
votes
8 answers

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

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…
newbie
  • 22,918
  • 75
  • 190
  • 297
19
votes
7 answers

Differences between session vs session factory - Hibernate?

Do we have any other differences other than the below? Also please validate whether the below are correct SessionFactory objects are one per application and Session objects are one per client. SessionFactory is to create and manage Sessions.…
user2323036
  • 1,257
  • 5
  • 18
  • 26
16
votes
4 answers

getting hibernate default schema name programmatically from session factory?

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…
John
  • 817
  • 3
  • 10
  • 19
16
votes
5 answers

Spring-Hibernate : Illegal attempt to associate a collection with two open sessions

I am trying to update record in MySql Db. while updating it threw following exception org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions at…
Manish Mahajan
  • 945
  • 1
  • 8
  • 33
14
votes
4 answers

Spring+Hibernate, Autowire sessionFactory into hibernate DAO

i have an Hibernate DAO, in according with Hibernate API 3 and Spring 3.x, I use simply a sessionFactory and NOT an HibernateDaoSupport+getHibernateTemplate() - i hope this is a good choice... - Now my goal is to autowire sessionFactory into my DAO…
blow
  • 11,391
  • 23
  • 66
  • 104
14
votes
2 answers

Ensure NHibernate SessionFactory is only created once

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…
stiank81
  • 24,500
  • 40
  • 125
  • 200
13
votes
2 answers

Hibernate Open Session in View: Transaction per Request?

I'm using Hibernate with Spring on Tomcat. I've been reading and re-reading the oft pointed to JBoss wiki page on the topic, and that has been helpful. But it leaves me with some questions. The idea of starting a transaction for every request…
Marvo
  • 16,808
  • 8
  • 46
  • 69
12
votes
1 answer

org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'sessionFactory'

I am using spring and hibernate for configuration with mysql db. My we.xml file has following code :
Nirmal
  • 4,739
  • 13
  • 70
  • 113
11
votes
3 answers

Select single item from database with Spring Hibernate Sessionfactory

This is in my DAO: public List getCurrentWeather() { return sessionFactory.getCurrentSession().createQuery("from Weather").list(); } This gets all of the elements from table Weather. But lets say I wanna do something like this(I want…
Jaanus
  • 15,013
  • 43
  • 137
  • 193
11
votes
2 answers

How do you test Spring @Transactional without just hitting hibernate level 1 cache or doing manual session flush?

Using Spring + Hibernate and transactional annotations. I'm trying to test the following: call a method that changes a User object then calls a @Transactional service method to persist it read the object back from the DB and insure it's values are…
9
votes
3 answers

What is the use of ServiceRegistry in creating SessionFactory

I am learning Hibernate in Java. Since, to create a Session, we have to use SessionFactory.openSession(), and for creating SessionFactory we use sessionFactory = config.buildSessionFactory(serviceRegistry); What is the use of ServiceRegistry in…
earthmover
  • 4,039
  • 10
  • 42
  • 73
9
votes
3 answers

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

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…
Andrew
  • 2,257
  • 4
  • 26
  • 40
1
2 3
28 29