在JBoss 5上部署Seam应用程序

由于本人英语水平和精力都有限,无法完成全部翻译,只是对其中重点文字作了翻译,依照这几处重点指示,应该就能把问题解决了,若欲详细探究请阅读英文原文,原文出处:http://code.google.com/p/seaminaction/wiki/DeployingToJBossAS5

 

DeployingToJBossAS5

在JBoss 5上部署Seam应用程序   


Provides guidance for running the sample application on JBoss AS 5

 

Overview

JBoss AS 5 is a fully compliant Java EE 5 application server. It was first released to the community in December 2008, post dating the release of the book by several months. This page documents migration problems that may be encountered running the sample application on JBoss AS 5 and guidance on how to get the deployment working.


Persistence unit problems

If you take the WAR version of the sample application and attempt to deploy it to JBoss AS 5, you likely get the following exception when you attempt to look at a listing page:

如果您将WAR版本的样例应用程序部署到JBoss AS 5上,在运行时,可能会得到如下的错误提示:

Caused by: java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: Facility is not mapped [select facility from Facility facility]

 

The problem stems from the fact that JBoss AS 5 handles the deployment of persistence units different than JBoss AS 4. Namely, JBoss AS 5 will load any persistence unit defined in META-INF/persistence.xml automatically. That means when Seam loads the persistence unit, there are now two runtime instances of the persistence unit. (In addition, JBoss AS 5 doesn't scan for entity classes in WEB-INF/classes when bootstrapping the persistence unit manually or in Seam). Either way, you only need to load the persistence unit once.

To fix the problem of how the persistence unit is loaded, make the following changes to the project.

要解决持久化单元的加载问题,须对项目的某些配置进行更改,接下来将教您具体如何做:

  • Instruct the Hibernate JPA provider to bind the runtime persistence unit to JNDI by adding this property to the resources/META-INF/persistence-*.xml files
  • 往/META-INF/persistence-*.xml配置文件中添加属性
<property name="jboss.entity.manager.factory.jndi.name" value="java:/open18EntityManagerFactory"/>
 

 

  • Disable the Seam-managed persistence unit in resources/WEB-INF/components.xml (or just remove this component definition altogether)
  • 修改/WEB-INF/components.xml中的配置节(或者干脆把这个配置节删除)
<persistence:entity-manager-factory name="open18EntityManagerFactory" persistence-unit-name="open18" installed="false"/>
 

 

  • Switch the Seam-managed persistence context to use the persistence unit in JNDI by modifying this component definition in resources/WEB-INF/components.xml
  • 修改/WEB-INF/components.xml中的配置节
<persistence:managed-persistence-context name="entityManager" auto-create="true" entity-manager-factory="#{open18EntityManagerFactory}" persistence-unit-jndi-name="java:/open18EntityManagerFactory"/>
 


This solution may seem a bit "hackish" because you are resorting to the proprietary JNDI binding that I spoke about in chapter 9. If you want to do it right, simply follow the instructions I give in chapter 9 for binding a persistence unit to JNDI on a Java EE 5 compliant server. Namely, define a persistence unit reference in web.xml:

<persistence-unit-ref>
    <persistence-unit-ref-name>open18/emf</persistence-unit-ref-name>
    <persistence-unit-name>open18</persistence-unit-name>  
</persistence-unit-ref>
 

Then use the following JNDI name in components.xml to refer to it:

java:comp/env/open18/emf

Retrieving the persistence unit runtime from JNDI is the only way in JBoss AS 5 to ensure the persistence unit loads once and Seam uses it. I am not sure at this point how to prevent JBoss AS 5 from automatically loading the persistence unit.

GlassFish handles this more correctly, in my mind. If the persistence unit reference is not defined in web.xml, then GlassFish doesn't load the persistence unit.


Further explanation

The reason this problem crops up is because Seam was designed under the assumption that the application server would not load persistence units in a WAR project (I talk about this in depth in chapter 9). JBoss AS 5 is compliant with Java EE 5 and therefore does load the persistence unit (well, the spec is loose here and JBoss AS 5 doesn't wait for a persistence unit reference to give the green light).


Resources

  • Running Seam Examples on JBoss AS - This page on the seamframework.org Knowledge Base gives the latest status of running the Seam distribution examples on JBoss AS. You'll notice that most problems surround the persistence issue described above.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值