public void createTopicMessage(EventModel em) throws Exception { logger.debug(" enter service: createMessage "); ForumMessage forumMessage = (ForumMessage)em.getModelIF(); Forum forum = forumBuilder.getForum(forumMessage.getForum().getForumId()); if (forum == null){ logger.error(" no this forum, forumId = " + forumMessage.getForum().getForumId()); em.setErrors(Constants.ERRORS); return; } forumMessage.setForum(forum); TransactionManager tx = jtaTransactionUtil.getTransactionManager(); try { tx.begin(); ForumThread forumThread = super.createThread(forumMessage); forumMessage.setForumThread(forumThread); messageDaoFacade.getMessageDao().createMessage(forumMessage); tx.commit(); } catch (Exception e) { logger.error(e); jtaTransactionUtil.rollback(tx); throw new Exception(e); } } <p>
session是否会在JTA事务结束之后关闭?如果会,那就避免不了LazyInitializationException异常了,要解决它又回到OSIV。
[该贴被oojdon于2008-11-10 17:30修改过]
你可以在事务内自己关闭session
如果你不想手工flush,让Hibernate自动flush,必须配置Hibernate的hibernate.transaction.manager_lookup_class 和 hibernate.transaction.factory_class
不是让Hibernate启动事务,而是让他自动侦测,他如果发现事务关闭,会自动auto flush
这些和Spring 的OSIV,没有关系,不要瞎猜,要理解原理,这里一篇文章:
http://blog.xebia.com/2008/07/18/configuring-hibernate-and-spring-for-jta/
[该贴被banq于2008-11-10 18:14修改过]
我把jivejdon用jboss再测试一下
猜你喜欢
本站原创《复杂软件设计之道:领域驱动设计全面解析与实战》