Announcement Announcement Module
Collapse
No announcement yet.
Transaction not successfully started. Spring/Hibernate integration error. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Transaction not successfully started. Spring/Hibernate integration error.

    Hi All,
    I am getting the following exception in my DAO class which is defined using @Transactional Annotation. Following is my DAO method code.

    Transaction not successfully started
    at org.hibernate.transaction.JDBCTransaction.commit(J DBCTransaction.java:131)
    at org.springframework.orm.hibernate3.HibernateTransa ctionManager.doCommit(HibernateTransactionManager. java:656)

    Code:
    public Users getUsersRoles(String userID, String pwd) {
    		Session session = sessionfactory.getCurrentSession();
    		List<Users> result = null;
                    Transaction transaction = null;
            try{
              transaction = session.beginTransaction();
    	  Query query = session.createQuery("from Users ur where ur.username=? and password=?");
    	  query.setString(0, userID);
    	  query.setString(1, pwd);
    	     result = (List<Users>) query.list();
    	     if(!transaction.wasCommitted())
    	    	 transaction.commit();
            }
            catch(Exception e){
            	transaction.rollback();
            }
            finally{
            	session.close();
            }
            if (result != null)
    	      {
    	    	  return result.get(0);
    	      }
    	    else
    	    {
    	    	  return null;
    	    }
    	}
    Any help would be highly appreciated.

    Thanks,
    Rajesh

  • #2
    Why on earth are yo messing around with transactions? You have spring to manage the transactions for you. So remove your transaction code.

    Comment


    • #3
      Hello Rajesh

      Consider read this carefully
      11. Transaction Management

      Comment

      Working...
      X