部署hibernate时出现NameAlreadyBoundException异常,是怎么回事??

hello kitty
05-05-18 4 612

我的EAR文件如下
-hrProject.ear
+hrHiberanteClasses.jar
+hrHibernate.sar
+hrManage.jar
+hrManageWeb.war
META-INF
hrHiberanteClasses.jar文件中部署的是映射类
hrHibernate.sar文件中部署的是hbm.xml文件
运行JBOSS时出现异常javax.naming.NameAlreadyBoundException; remaining name 'env'例如其中一个是10:26:24,140 WARN [ServiceController] Problem starting service jboss.j2ee:jndiName=RoleManage,service=EJB
javax.naming.NameAlreadyBoundException; remaining name 'env',并且其他EJB也出现这样的错误.请问这是真么回是,我把持久类文件hrHibernate.sar和META-INF/jboss-app.xml删掉就是正常的
META-INF/jboss-app.xml内容如下:
<jboss-app>
<loader-repository>hrProject:loader=hrProject.ear</loader-repository>
<module>
<service>hrHibernate.sar</service>
</module>

</jboss-app>
META-INF/application.xml内容如下:
<application>
<display-name>MY HRProject</display-name>

<module>
<web>
<web-uri>hrManageWeb.war</web-uri>
<context-root>/hrProject</context-root>
</web>
</module>

<module>
<java>hrHiberanteClasses.jar</java>
</module>

<module>
<ejb>hrManage.jar</ejb>
</module>

</application>
hrHibernate.sar/META-INF/jboss-service.xml内容如下:
<server>
<mbean code="net.sf.hibernate.jmx.HibernateService" name="jboss.jca:service=HibernateFactory">
<!--<depends>jboss.jca:service=RARDeployer</depends>
<depends>jboss.jca:service=LocalTxCM,name=searchDS</depends>-->
<!-- Make it deploy ONLY after DataSource had been started -->
<!-- Map file -->
<attribute name="MapResources">
cn\com\hzh\hibernate\UserInfo.hbm.xml
cn\com\hzh\hibernate\UserInfo2.hbm.xml
cn\com\hzh\hibernate\UserRole.hbm.xml
cn\com\hzh\hibernate\UsersRoles.hbm.xml
</attribute>

<attribute name="JndiName">java:comp/env/hibernate/MySessionFactory</attribute>
<attribute name="Datasource">java:/MySql</attribute>
<attribute name="Dialect">net.sf.hibernate.dialect.MySQLDialect</attribute>
<attribute name="TransactionStrategy">net.sf.hibernate.transaction.JTATransactionFactory</attribute>
<attribute name="TransactionManagerLookupStrategy">net.sf.hibernate.transaction.JBossTransactionManagerLookup</attribute>
<attribute name="UseOuterJoin">true</attribute>
<attribute name="ShowSql">true</attribute>
<attribute name="UserTransactionName">java:/UserTransaction</attribute>
<!--<attribute name="hibernate.cache.provider_class">net.sf.hibernate.cache.HashtableCacheProvider</attribute>-->
</mbean>
</server>

hello kitty
2005-05-18 13:05

META-INF/jboss-app.xml内容如下:

<jboss-app>
<loader-re
<module>
<service
</module>

</jboss-app>

META-INF/application.xml内容如下:

<application>
<display-name>MY HRProject</display-name>

<module>
<web>
<web-uri>hrManageWeb.war</web-uri>
<context-root>/hrProject</context-root>
</web>
</module>

<module>
<java>hrHiberanteClasses.jar</java>
</module>

<module>
<ejb>hrManage.jar</ejb>
</module>

</application>

hrHibernate.sar/META-INF/jboss-service.xml内容如下:

<server>
<mbean code="net.sf.hibernate.jmx.HibernateService" name="jboss.jca:service=HibernateFactory">
<!--<depends>jboss.jca:service=RARDeployer</depends>
<depends>jboss.jca:service=LocalTxCM,name=searchDS</depends>-->
<!-- Make it deploy ONLY after DataSource had been started -->
<!-- Map file -->
<attribute name=
"MapResources">
cn\com\hzh\hibernate\UserInfo.hbm.xml
cn\com\hzh\hibernate\UserInfo2.hbm.xml
cn\com\hzh\hibernate\UserRole.hbm.xml
cn\com\hzh\hibernate\UsersRoles.hbm.xml
</attribute>

<attribute name=
"JndiName">java:comp/env/hibernate/MySessionFactory</attribute>
<attribute name=
"Datasource">java:/MySql</attribute>
<attribute name=
"Dialect">net.sf.hibernate.dialect.MySQLDialect</attribute>
<attribute name=
"TransactionStrategy">net.sf.hibernate.transaction.JTATransactionFactory</attribute>
<attribute name=
"TransactionManagerLookupStrategy">net.sf.hibernate.transaction.JBossTransactionManagerLookup</attribute>
<attribute name=
"UseOuterJoin">true</attribute>
<attribute name=
"ShowSql">true</attribute>
<attribute name=
"UserTransactionName">java:/UserTransaction</attribute>
<!--<attribute name=
"hibernate.cache.provider_class">net.sf.hibernate.cache.HashtableCacheProvider</attribute>-->
</mbean>
</server>

kalparser
2005-05-21 22:53

I think the problem is that you are not allowed to do ANYTHING in your EJB constructor that requires the container environment. Look at the operations allowed in the methods of a stateless session bean table in the EJB spec. For the bean constructor line there are no operations allowed.

The attempt to lookup the component ENC in the constructor is causing the ENC to be associated with a class loader that is not unique to the EJB and this results in the duplicate binding attempt when the second session bean is deployed.

All of your setup work should be done in the ejbCreate() method.

hello kitty
2005-05-23 16:19

请问应该在ejbCreate方法中做些什么事情,能不能说得具体些,谢谢!

kalparser
2005-05-24 00:03

what i meant was that probably you put something in your ejb constructor which is not allowed to do, for instance maybe some initialization?
and the problem could also be that two or more beans are using the same context classloader.