Jboss 7 と Hibernate 4 で Seam3 を使用して Web アプリケーションを正しく構成するには、あなたの助けが必要です。
EntityManager を注入して使用しようとすると、entitymanager の結果が NULL になりますが、Persistence.createEntityManagerFactory("myPU").createEntityManager() で EntityManager を取得しようとすると、結果は正しいです。
これは私のpersistence.xmlです
<?xml version="1.0" encoding="UTF-8"?>
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="accbetaPU" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>accbeta</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
<property name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.JBossTransactionManagerLookup" />
<property name="hibernate.archive.autodetection" value="class" />
</properties>
</persistence-unit>
これは私の EntityManagerProducer です
@ApplicationScoped
public class EntityManagerProducer{
@PersistenceContext
private EntityManager entityManager;
@Produces
public EntityManager getEntityManager() {
return entityManager;
}
}
これは私の /Web-INF/beans.xml です
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
<interceptors>
<class>org.jboss.seam.faces.context.conversation.ConversationBoundaryInterceptor</class>
<class>org.jboss.seam.transaction.TransactionInterceptor</class>
</interceptors>
</beans>
そして、これはテストEntityManagerの私のクラスです...
@ApplicationScoped
@Named("first")
public class first implements Serializable{
private static final long serialVersionUID = -1625566649081574918L;
private String testBenvenuto;
@Inject
private EntityManager entityManager;
public first() {
this.testBenvenuto = "Welcome";
starting();
}
public void starting(){
this.testBenvenuto = this.testBenvenuto+" "+entityManager;
this.testBenvenuto = this.testBenvenuto+" "+Persistence.createEntityManagerFactory("accbetaPU").createEntityManager().toString();
}
public String getTestBenvenuto() {
return testBenvenuto;
}
public void setTestBenvenuto(String testBenvenuto) {
this.testBenvenuto = testBenvenuto;
}
}
JBOSS As7 でデプロイ (WAR) しようとすると、アプリケーションは例外なくデプロイされます...
数時間後..
EntityManagerProducer でこのコードを使用しようとしました:
@ExtensionManaged
@ConversationScoped
@Produces
@PersistenceUnit(unitName="accbetaPU")
EntityManagerFactory emf;
しかし、展開中にこのエラーが発生しました:
16:14:03,550 INFO [org.jboss.solder.core.CoreExtension] (MSC service thread 1-1) Preventing class org.jboss.seam.international.locale.LocaleConfiguration from being installed as bean due to @Veto annotation
16:14:05,715 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-1) MSC00001: Failed to start service jboss.deployment.unit."accbeta.war".WeldService: org.jboss.msc.service.StartException in service jboss.deployment.unit."accbeta.war".WeldService: org.jboss.weld.exceptions.DefinitionException: WELD-001502 Resource producer field [Resource Producer Field [EntityManagerFactory] with qualifiers [@Any @Default] declared as [[field] @PersistenceUnit @ConversationScoped @Produces startup.first.emf]] must be @Dependent scoped
at org.jboss.as.weld.services.WeldService.start(WeldService.java:96)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1824) [jboss-msc-1.0.1.GA.jar:1.0.1.GA]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1759) [jboss-msc-1.0.1.GA.jar:1.0.1.GA]
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_25]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_25]
at java.lang.Thread.run(Thread.java:662) [:1.6.0_25]
Caused by: org.jboss.weld.exceptions.DefinitionException: WELD-001502 Resource producer field [Resource Producer Field [EntityManagerFactory] with qualifiers [@Any @Default] declared as [[field] @PersistenceUnit @ConversationScoped @Produces startup.first.emf]] must be @Dependent scoped
at org.jboss.weld.bean.builtin.ee.EEResourceProducerField.checkEEResource(EEResourceProducerField.java:133)
at org.jboss.weld.bean.builtin.ee.EEResourceProducerField.initialize(EEResourceProducerField.java:125)
at org.jboss.weld.bootstrap.AbstractBeanDeployer.deploy(AbstractBeanDeployer.java:119)
at org.jboss.weld.bootstrap.BeanDeployment.deployBeans(BeanDeployment.java:227)
at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:378)
at org.jboss.as.weld.WeldContainer.start(WeldContainer.java:81)
at org.jboss.as.weld.services.WeldService.start(WeldService.java:89)
... 5 more
16:14:05,715 INFO [org.jboss.as.controller] (DeploymentScanner-threads - 2) Service status report
Services which failed to start:
service jboss.deployment.unit."accbeta.war".WeldService: org.jboss.msc.service.StartException in service jboss.deployment.unit."accbeta.war".WeldService: org.jboss.weld.exceptions.DefinitionException: WELD-001502 Resource producer field [Resource Producer Field [EntityManagerFactory] with qualifiers [@Any @Default] declared as [[field] @PersistenceUnit @ConversationScoped @Produces startup.first.emf]] must be @Dependent scoped
WELD-001502 リソース プロデューサ フィールド [[フィールド] @PersistenceUnit @ConversationScoped @Produces startup.first.emf] として宣言された修飾子 [@Any @Default] を持つリソース プロデューサ フィールド [EntityManagerFactory] は @Dependent スコープである必要があります
私は何をすべきか?何が欠けていますか?
以下は、war ファイル内のライブラリのリストです。
commons-beanutils-1.8.0.jar
commons-digester-2.1.jar
commons-logging-1.1.1.jar
cssparser-0.9.5.jar
guava-0.9.jar
hibernate-entitymanager-4.0.0.CR1.jar
jboss-servlet-api_3.0_spec-1.0.0.Final.jar
joda-time-1.6.jar
log4j-1.2.16.jar
ocpsoft-pretty-time-1.0.6.jar
picketlink-idm-api-1.5.0.Alpha02.jar
picketlink-idm-common-1.5.0.Alpha02.jar
picketlink-idm-core-1.5.0.Alpha02.jar
picketlink-idm-spi-1.5.0.Alpha02.jar
postgresql-9.0-801.jdbc4.jar
prettyfaces-jsf2-3.2.0.jar
richfaces-components-api-4.2.1.Final.jar
richfaces-components-ui-4.2.1.Final.jar
richfaces-core-api-4.2.1.Final.jar
richfaces-core-impl-4.2.1.Final.jar
sac-1.3.jar
seam-faces-3.1.0.Final.jar
seam-faces-api-3.1.0.Final.jar
seam-international-3.1.0.Final.jar
seam-international-api-3.1.0.Final.jar
seam-persistence-3.1.0.Final.jar
seam-persistence-api-3.1.0.Final.jar
seam-security-3.1.0.Final.jar
seam-security-api-3.1.0.Final.jar
slf4j-api-1.6.1.jar
slf4j-simple-1.6.1.jar
solder-api-3.1.0.Final.jar
solder-impl-3.1.0.Final.jar
solder-logging-3.1.0.Final.jar
Jboss のバージョンは 7.0.2 です
お願い助けて
あなたの答えをありがとう..私は削除しようとしましたが、効果はhibernate-entitymanager-4.0.0.CR1.jar
ありjboss-servlet-api_3.0_spec-1.0.0.Final.jar
ません!
persistence.xml も変更しました
<persistence-unit name="accbetaPU">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/datasources/AccbetaDS</jta-data-source>
<properties>
<!-- Properties for Hibernate (default provider for JBoss AS) -->
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.show_sql" value="true"/>
<!-- Only format when you need to debug, because it slows things down -->
<property name="hibernate.format_sql" value="false"/>
<property name="hibernate.show_sql" value="false"/>
<property name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.JBossTransactionManagerLookup" />
</properties>
</persistence-unit>
この方法でエンティティマネージャーを作成しようとすると...
@ExtensionManaged
@ConversationScoped
@Produces
@PersistenceUnit(unitName="accbetaPU")
EntityManagerFactory emf;
エラーは同じです....
17:11:20,589 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-4) MSC00001: Failed to start service jboss.deployment.unit."accbeta.war".WeldService: org.jboss.msc.service.StartException in service jboss.deployment.unit."accbeta.war".WeldService: org.jboss.weld.exceptions.DefinitionException: WELD-001502 Resource producer field [Resource Producer Field [EntityManagerFactory] with qualifiers [@Any @Default] declared as [[field] @ConversationScoped @PersistenceUnit @Produces startup.first.emf]] must be @Dependent scoped
at org.jboss.as.weld.services.WeldService.start(WeldService.java:96)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1824) [jboss-msc-1.0.1.GA.jar:1.0.1.GA]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1759) [jboss-msc-1.0.1.GA.jar:1.0.1.GA]
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_25]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_25]
at java.lang.Thread.run(Thread.java:662) [:1.6.0_25]
Caused by: org.jboss.weld.exceptions.DefinitionException: WELD-001502 Resource producer field [Resource Producer Field [EntityManagerFactory] with qualifiers [@Any @Default] declared as [[field] @ConversationScoped @PersistenceUnit @Produces startup.first.emf]] must be @Dependent scoped
at org.jboss.weld.bean.builtin.ee.EEResourceProducerField.checkEEResource(EEResourceProducerField.java:133)
at org.jboss.weld.bean.builtin.ee.EEResourceProducerField.initialize(EEResourceProducerField.java:125)
at org.jboss.weld.bootstrap.AbstractBeanDeployer.deploy(AbstractBeanDeployer.java:119)
at org.jboss.weld.bootstrap.BeanDeployment.deployBeans(BeanDeployment.java:227)
at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:378)
at org.jboss.as.weld.WeldContainer.start(WeldContainer.java:81)
at org.jboss.as.weld.services.WeldService.start(WeldService.java:89)
... 5 more
17:11:20,605 INFO [org.jboss.as.controller] (DeploymentScanner-threads - 2) Service status report
Services which failed to start:
service jboss.deployment.unit."accbeta.war".WeldService: org.jboss.msc.service.StartException in service jboss.deployment.unit."accbeta.war".WeldService: org.jboss.weld.exceptions.DefinitionException: WELD-001502 Resource producer field [Resource Producer Field [EntityManagerFactory] with qualifiers [@Any @Default] declared as [[field] @ConversationScoped @PersistenceUnit @Produces startup.first.emf]] must be @Dependent scoped
あなたの答えをありがとう..私は削除しようとしましたが、効果はhibernate-entitymanager-4.0.0.CR1.jar
ありjboss-servlet-api_3.0_spec-1.0.0.Final.jar
ません!
persistence.xml も変更しました
<persistence-unit name="accbetaPU">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/datasources/AccbetaDS</jta-data-source>
<properties>
<!-- Properties for Hibernate (default provider for JBoss AS) -->
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.show_sql" value="true"/>
<!-- Only format when you need to debug, because it slows things down -->
<property name="hibernate.format_sql" value="false"/>
<property name="hibernate.show_sql" value="false"/>
<property name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.JBossTransactionManagerLookup" />
</properties>
</persistence-unit>
エンティティマネージャーを作成しようとすると、エラーは同じです....