Hibernate 4.1.5.SP1 を使用していますが、注釈ベースのクラスで使用するためのセッション ファクトリの構成に問題があります。私はそれを試して設定します
final Configuration hibConfiguration = new Configuration().configure();
final ServiceRegistry serviceRegistry = new ServiceRegistryBuilder()
.applySettings(hibConfiguration.getProperties())
.buildServiceRegistry();
return hibConfiguration.buildSessionFactory(serviceRegistry);
しかし、私はこの例外を受け取ります ("An AnnotationConfiguration instance is required to use
org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: javax.ejb.EJBTransactionRolledbackException: An AnnotationConfiguration instance is required to use <mapping class="com.mainco.fdr.myproject.model.UserRole"/>]
at org.quartz.core.JobRunShell.run(JobRunShell.java:214)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:520)
* Nested Exception (Underlying Cause) ---------------
javax.ejb.EJBTransactionRolledbackException: org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:87) で使用するには、AnnotationConfiguration インスタンスが必要です。 ) org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) で org.jboss.ejb3.stateless でStatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62) org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) org.jboss.ejb3.mdb.MessagingContainer.localInvoke(MessagingContainer.java:249) org org.jboss.ejb3.mdb の .jboss.ejb3.mdb.inflow.MessageInflowLocalProxy.delivery(MessageInflowLocalProxy.java:268)。$Proxy128 の inflow.MessageInflowLocalProxy.invoke(MessageInflowLocalProxy.java:138) org.jboss.resource.adapter.quartz.inflow.QuartzJob.execute(QuartzJob.java:57) の org.quartz.core .JobRunShell.run(JobRunShell.java:203) at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:520) 原因: org.hibernate.MappingException: org.hibernate で使用するには AnnotationConfiguration インスタンスが必要です.cfg.Configuration.parseMappingElement(Configuration.java:1600) org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1555) org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1534) org. org.hibernate.cfg.Configuration の hibernate.cfg.Configuration.doConfigure(Configuration.java:1508)。configure(Configuration.java:1428) org.subco.myco.dido.service.AbstractServiceProvider.getSessionFactory(AbstractServiceProvider.java:64) で org.subco.subco で.myco.dido.service.AbstractServiceProvider.initServices(AbstractServiceProvider.java:127) で org.subco.myco.dido.quartz.ProcessOrdersJob.execute(ProcessOrdersJob.java:79) で sun.reflect.NativeMethodAccessorImpl.invoke0(ネイティブ メソッド) org の java.lang.reflect.Method.invoke(Method.java:597) でorg.jboss.ejb3 の jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)。interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166) org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptorInterceptor.invoke(EJB3InterceptorsInterceptor.java:63) org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54) で org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) で org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor) .java:47) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126) ... 11 詳細166) org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63) で org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) で org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor .invoke(TransactionScopedEntityManagerInterceptor.java:54) org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47) org.jboss. aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126) ... 11 詳細166) org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63) で org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) で org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor .invoke(TransactionScopedEntityManagerInterceptor.java:54) org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47) org.jboss. aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126) ... 11 詳細MethodInvocation.invokeNext(MethodInvocation.java:101) org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54) org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) org .jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47) org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java) :126) ... 11 件以上MethodInvocation.invokeNext(MethodInvocation.java:101) org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54) org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) org .jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47) org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java) :126) ... 11 件以上ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47) の org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) の org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126) ... 11以上ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47) の org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) の org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126) ... 11以上
ここに私のMavenの依存関係があります
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.3.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
<exclusions>
<exclusion>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.1_spec</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
そして、これが私の hibernate.cfg.xml ファイルです…</p>
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.datasource">MySqlDS</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<mapping class="com.mainco.fdr.myproject.model.UserRole" />
<mapping class="com.mainco.fdr.myproject.model.Organization" />
<mapping class="com.mainco.fdr.myproject.model.Product" />
<mapping class="com.mainco.fdr.myproject.model.State" />
<mapping class="com.mainco.fdr.myproject.model.Country" />
<mapping class="com.mainco.fdr.myproject.model.AccessCode" />
<mapping class="com.mainco.fdr.myproject.model.Contract" />
<mapping class="com.mainco.fdr.myproject.model.TrainingLink" />
</session-factory>
</hibernate-configuration>
アプリケーションを JAR ファイルとして JBoss 4.2.2.GA サーバーに返信しています (JBoss のバージョンを制御できません)。含める必要がある適切な依存関係と、以下のような注釈ベースのクラスを読み取れるようにセッション ファクトリを構成する正しい方法は何ですか …</p>
@Entity
@Table(name = "lyc_user_role")
public class UserRole {
@Id
@Column(name = "USER_ROLE_ID")
private String roleId;