michaelisvy / hibernate-4-spring-3.1-samples

showcases how to integrate Spring 3.1 and Hibernate 4 (with or without JPA)
77 stars 90 forks source link

sessionFactory.getCurrentSession(); #1

Open ghost opened 12 years ago

ghost commented 12 years ago

i have open session in oracle and session limit problem when i use getSession.openSession();//session limit in oracle and sessionFactory.getCurrentSession();//have problem in that session not exist in thread i config @transcation by i get not open session in lazy loading (session close)

i dont know how do it plz help meeee plzzzzz

@Autowired private SessionFactory sessionFactory;

@Override
public List<T> getAll() {
    Criteria criteria = getSession().createCriteria(domainClass.getName());
    return criteria.list();
}

public Session getSession() {
        return sessionFactory.getCurrentSession();
}
michaelisvy commented 12 years ago

Hi Ali, your code sample looks good to me (assuming that you did inject the sessionFactory properly as in my sample application). So it might be that you're having issues in your Oracle datasource configuration. Sorry I can't help you on that specific point but I'm sure you'll find plenty of examples on Internet. You can also ask on the Spring forums here: http://forum.springsource.org/forumdisplay.php?27-Data

Cheers, Michael.

faroe228 commented 11 years ago

So how does one make this example work when it is not being run as a JUnit test? I can't get the transactional part to work outside of JUnit and always get a org.hibernate.HibernateException: No Session found for current thread.

pandahk commented 8 years ago

so same