在JBoss 5上部署Seam应用程序

本文档指导如何在JBoss AS5上部署Seam应用程序,解决持久化单元加载问题,包括修改配置文件以绑定持久化单元到JNDI,禁用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.
内容概要:本文系统介绍了算术优化算法(AOA)的基本原理、核心思想及Python实现方法,并通过图像分割的实际案例展示了其应用价值。AOA是一种基于种群的元启发式算法,其核心思想来源于四则运算,利用乘除运算进行全局勘探,加减运算进行局部开发,通过数学优化器加速函数(MOA)和数学优化概率(MOP)动态控制搜索过程,在全局探索与局部开发之间实现平衡。文章详细解析了算法的初始化、勘探与开发阶段的更新策略,并提供了完整的Python代码实现,结合Rastrigin函数进行测试验证。进一步地,以Flask框架搭建前后端分离系统,将AOA应用于图像分割任务,展示了其在实际工程中的可行性与高效性。最后,通过收敛速度、寻优精度等指标评估算法性能,并提出自适应参数调整、模型优化和并行计算等改进策略。; 适合人群:具备一定Python编程基础和优化算法基础知识的高校学生、科研人员及工程技术人员,尤其适合从事人工智能、图像处理、智能优化等领域的从业者;; 使用场景及目标:①理解元启发式算法的设计思想与实现机制;②掌握AOA在函数优化、图像分割等实际问题中的建模与求解方法;③学习如何将优化算法集成到Web系统中实现工程化应用;④为算法性能评估与改进提供实践参考; 阅读建议:建议读者结合代码逐行调试,深入理解算法流程中MOA与MOP的作用机制,尝试在不同测试函数上运行算法以观察性能差异,并可进一步扩展图像分割模块,引入更复杂的预处理或后处理技术以提升分割效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值