hibernate问题:Transaction not successfully started
hibernate问题:Transaction not successfully started
测试类:import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
public class Test {
x05public static void main(String[] args) {
x05x05
x05x05Configuration conf=new Configuration().configure();
x05x05SessionFactory sf=conf.buildSessionFactory();
x05x05Session session=sf.openSession();
x05x05Transaction tx=null;
x05x05try{
x05x05x05tx=session.getTransaction();
x05x05x05User user=new User();
x05x05x05user.setUname("username");
x05x05x05user.setUpass("password");
x05x05x05session.save(user);
x05x05x05tx.commit();
x05x05}catch(Exception e){
x05x05x05if(null!=tx){
x05x05x05x05tx.rollback();
x05x05x05}
x05x05x05e.printStackTrace();
x05x05}finally{
x05x05x05session.close();
x05x05}
x05}
}
报错信息:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.hibernate.TransactionException:Transaction not successfully started
x05at org.hibernate.transaction.JDBCTransaction.rollback(JDBCTransaction.java:149)
x05at cn.hibernate.entity.Test.main(Test.java:32)