如题,,
如何在glassfish中使用hibernate jta事务控制呢?
我搞了半天了,不报错,但是就是插不了数据库
如何在glassfish中使用hibernate jta事务控制呢?
我搞了半天了,不报错,但是就是插不了数据库
解决方案 »
- apache rewriterule 子目录重写,高手in
- 这是什么错误啊。。当我在保存一个实体时出现的错误。。。
- struts2.0与2.1之间问题
- 用myeclipse创建的struts项目中的web.xml没有taglib描述???????????
- hibernate多表继承问题求教!
- html:javascript与jsp:include冲突,怎么解决
- sf 给eric!
- 安装memcache时出现的问题,求大师指点
- 有人研究过BIE吗?能否提供些相关资料?多谢!
- 单元测试,怎么让spring管理事务又不污染数据库
- java 等待进度条
- could not find PropertyAccessor class: method是一个什么错误?怎么解决?
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration> <session-factory>
<property name="connection.username">root</property>
<property name="connection.url">
jdbc:mysql://localhost/soundcard
</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="myeclipse.connection.profile">mysql</property>
<property name="connection.password">root</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="hibernate.transaction.manager_lookup_class">
org.hibernate.transaction.SunONETransactionManagerLookup
</property>
<property name="hibernate.current_session_context_class">org.hibernate.context.JTASessionContext</property>
<property name="jta.UserTransaction">java:comp/UserTransaction</property>
<property name="hibernate.transaction.factory_class">
org.hibernate.transaction.JTATransactionFactory
</property>
<property name="show_sql">true</property>
<!--
-->
<mapping resource="com/soundcard/bean/Role.hbm.xml" />
<mapping resource="com/soundcard/bean/Log.hbm.xml" />
<mapping resource="com/soundcard/bean/Communication.hbm.xml" />
<mapping resource="com/soundcard/bean/User.hbm.xml" />
<mapping resource="com/soundcard/bean/Permission.hbm.xml" />
<mapping resource="com/soundcard/bean/UserRole.hbm.xml" />
<mapping resource="com/soundcard/bean/Blacklist.hbm.xml" />
<mapping resource="com/soundcard/bean/RolePermission.hbm.xml" /> </session-factory></hibernate-configuration>
User user = new User();
user.setUserid(userid);
user.setPassword(Utils.toMD5Normal(password));
user.setName(username);
user.setPhone(phone);
UserRoleId userRoleId = new UserRoleId();
userRoleId.setRoleid(roleid);
userRoleId.setUserid(userid);
UserRole userRole = new UserRole();
userRole.setId(userRoleId);
UserTransaction tx = null;
try {
tx = (UserTransaction)new InitialContext().lookup("java:comp/UserTransaction");
} catch (NamingException e) {
e.printStackTrace();
}
try {
tx.begin();
} catch (NotSupportedException e1) {
e1.printStackTrace();
} catch (SystemException e1) {
e1.printStackTrace();
}
IUserDao userDao = new UserDAO();
try {
userDao.save(user);
}catch(Exception e) {
try {
tx.rollback();
} catch(Exception re) {
re.printStackTrace();
}
}
IUserRoleDao userRoleDao = new UserRoleDAO();
try {
userRoleDao.save(userRole);
} catch(Exception e) {
try {
tx.rollback();
} catch(Exception re) {
re.printStackTrace();
}
}
try {
tx.commit();
} catch (Exception e) {
e.printStackTrace();
}