Transactional not able to resolve transaction boundaries - Hibernate

53 Views Asked by At

I am trying to do a simple saveOrUpdate operation using a Transaction Manager in Hibernate but, the context is not flushed to the DB tables. I suspect, the Transaction Manager is not able to resolve the end of the transaction and hence, doesn't flush the changes.

The changes are reflected in the DB Table if a session.flush() is done explicitly. I am using the Default flush mode, which is AUTO.

There are a couple of other questions on SO that talk about the same, but none of them have helped in my case.

@Transactional(transactionManager="txManager", readOnly=false)
    public Integer setNamesTable(Names names) {
    session = getSession();
    Integer id = null;
    if (session != null) {
        try {
            id = (Integer) session.save(names);
        } catch (Exception ex) {
            System.out.println(ex);
        } 
        LOGGER.info("Exiting setNmlAggrTcaPhn");
        }
    return id;
}

Have Autowired SessionFactory as below,

@Autowired
@Qualifier("hibernateTestAnnotatedSessionFactory")
SessionFactory sfc;

private synchronized Session getSession() {
    try {
            session = sf.getCurrentSession();
            if (session != null) {
            return session;
            } else {
            session = sf.openSession();
            }
        } catch (HibernateException ex) {
            session = sf.openSession();
        }
    return session;
    }
0

There are 0 best solutions below