日期:2014-05-20 浏览次数:20805 次
public void test(){ User user=new User(); user.setUserName("lisi"); UserManager userManager=new UserManagerImpl(); userManager.addUser(user); }
public class UserManagerImpl implements UserManager{ private LogManager logManager=new LogManagerImpl(); public void addUser(User user) { Session session=null; Transaction tx=null; try { session = HibernateSessionFactory.getSessionFactory() .getCurrentSession(); tx=session.beginTransaction(); session.save(user); Log log = new Log(); log.setType("anquanrizi"); Integer.parseInt("asdfasf"); log.setCont("XXX jinru xitong"); logManager.addLog(log); tx.commit(); } catch (RuntimeException e) { tx.rollback(); } } public void setLogManager(LogManager logManager) { this.logManager = logManager; } }
package com.log.manager; import org.hibernate.Session; import com.HibernateSessionFactory; import com.log.entity.Log; public class LogManagerImpl implements LogManager{ public void addLog(Log log) { Session session=null; session = HibernateSessionFactory.getSessionFactory() .getCurrentSession(); session.save(log); } }