This must be written in Basedaoimpl if you want to be public. Because this is to inherit the Hibernatedaosupport, and then in the DAO and other related to inherit, implement
Session= gethibernatetemplate (). Getsessionfactory (). Opensession ();
That's the key. A org.springframework.transaction.TransactionSystemException is always reported when the sentence is not written:
Could not commit Hibernate transaction; Nested exception is org.hibernate.TransactionException:Transaction not successfully started
At Org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit (hibernatetransactionmanager.java:661 )
However, after using the Opensession method, you must manually close the Session.close () in the back.
/****
* This is an operation that uses transactions to batch operations the user simply passes in the collection of HQL,
*/
Public List <String> deletesitebysite (final list<string> list)
{
TODO auto-generated Method Stub
Return (List <String>) this.gethibernatetemplate (). Execute (New Hibernatecallback ()
{
Public Object Doinhibernate (session session) throws Hibernateexception, SQLException
{
List <String> result=new arraylist<string> ();
Session= gethibernatetemplate (). Getsessionfactory (). Opensession ();
Session.begintransaction ();
TODO auto-generated Method Stub
Try
{
String re= "";
for (int i=0; i<list.size (); i++)
{
int a = Session.createsqlquery (List.get (i)). Executeupdate ();
if (a<0)
{
re=re+ "*";
}
}
if (re== "")
{
Session.gettransaction (). commit ();
Result.add ("Success");
}
Else
{
Session.gettransaction (). rollback ();
Result.add ("error");
}
}
catch (Exception e)
{
Session.gettransaction (). rollback ();
Result.add ("error");
}
Finally{session.close ();}
return result;
}
});
}
Attach two images in error for later inspection
The use of Java transactions