Guest User

Untitled

a guest
Aug 26th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. Why do I get org.hibernate.HibernateException: No CurrentSessionContext configured
  2. org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
  3.  
  4. Session sess = HibernateUtil.getSession();
  5. Transaction tx = sess.beginTransaction();
  6. try {
  7. tx.begin();
  8. sess.delete(ims);
  9. } catch (Exception e) {
  10. tx.rollback();
  11. throw e;
  12. }
  13. tx.commit();
  14. sess.flush();
  15.  
  16. public static Session getSession()
  17. throws HibernateException {
  18. Session sess = null;
  19. try {
  20. sess = sessionFactory.getCurrentSession();
  21. } catch (org.hibernate.HibernateException he) {
  22. sess = sessionFactory.openSession();
  23. }
  24. return sess;
  25. }
  26.  
  27. <hibernate-configuration>
  28. <session-factory >
  29. <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
  30. <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
  31. <property name="hibernate.connection.url">jdbc:mysql://localhost/joptel</property>
  32. <property name="hibernate.connection.username">root</property>
  33. <property name="hibernate.connection.password">******</property>
  34. <property name="hibernate.connection.pool_size">1</property>
  35. <property name="show_sql">true</property>
  36. <property name="hibernate.hbm2ddl.auto">update</property>
  37.  
  38.  
  39. ..mappings..
  40.  
  41. </session-factory>
  42. </hibernate-configuration>
  43.  
  44. public static Session getSession()
  45. throws HibernateException {
  46. Session sess = null;
  47. try {
  48. sess = sessionFactory.getCurrentSession();
  49. } catch (org.hibernate.HibernateException he) {
  50. sess = sessionFactory.openSession();
  51. } return sess; }
  52.  
  53. <property name="hibernate.current_session_context_class">thread</property>
  54.  
  55. <property name="hibernate.current_session_context_class">...</property>
Add Comment
Please, Sign In to add comment