Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Why do I get org.hibernate.HibernateException: No CurrentSessionContext configured
- org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
- Session sess = HibernateUtil.getSession();
- Transaction tx = sess.beginTransaction();
- try {
- tx.begin();
- sess.delete(ims);
- } catch (Exception e) {
- tx.rollback();
- throw e;
- }
- tx.commit();
- sess.flush();
- public static Session getSession()
- throws HibernateException {
- Session sess = null;
- try {
- sess = sessionFactory.getCurrentSession();
- } catch (org.hibernate.HibernateException he) {
- sess = sessionFactory.openSession();
- }
- return sess;
- }
- <hibernate-configuration>
- <session-factory >
- <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
- <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
- <property name="hibernate.connection.url">jdbc:mysql://localhost/joptel</property>
- <property name="hibernate.connection.username">root</property>
- <property name="hibernate.connection.password">******</property>
- <property name="hibernate.connection.pool_size">1</property>
- <property name="show_sql">true</property>
- <property name="hibernate.hbm2ddl.auto">update</property>
- ..mappings..
- </session-factory>
- </hibernate-configuration>
- public static Session getSession()
- throws HibernateException {
- Session sess = null;
- try {
- sess = sessionFactory.getCurrentSession();
- } catch (org.hibernate.HibernateException he) {
- sess = sessionFactory.openSession();
- } return sess; }
- <property name="hibernate.current_session_context_class">thread</property>
- <property name="hibernate.current_session_context_class">...</property>
Add Comment
Please, Sign In to add comment