Reputation: 33
Thanks for Reply :) My web application configuration like grails 2.4.4 version, hibernate 4.3.6 final version along with spring-core-4.0.7.RELEASE.
i am performing like
Session session2 = sessionFactory.getCurrentSession();
session2.persist(Obj);
session2.flush();
Transaction tx = session2.getTransaction();
log.debug("ITS CREATED??")
if(tx.isActive())
{
log.debug("ITS ACTIVE")
if(!tx.wasCommitted())
{
log.debug("NOT COMMITTED")
tx.commit();
}else
{
log.debug(" COMMITTED")
}
}else
{
log.debug("NOT ACTIVE")
}
Here when the execution is hitting the tx.commit() is throwing this kind of exception.
Am i missing something here? Please guide me.
Example:
class MetaDataController
{
def saveService;
def save={
def returnParams = saveService.doSave(params);
//Here returning to the controller, its giving an exception.
}
}
class SaveService
{
def transactional = true;
def doSave(def params)
{
def params;
Session session2 = sessionFactory.getCurrentSession();
Metadata metaData = new MetaData();
///Object association
session2.persist(metaData);
session2.flush();
Transaction tx = session2.getTransaction();
if(!tx.wasCommitted())
{
log.debug("NOT COMMITTED")
tx.commit();
}
return params;
}
}
Upvotes: 0
Views: 1692
Reputation: 9885
You don't need to mess around with sessions and transactions for such a simple use case. You're using Grails, remember?
class SaveService
{
def transactional = true;
def doSave(def params)
{
Metadata metaData = new MetaData()
metadata.save()
return params // I don't get this, but what the hell.
}
}
Upvotes: 1