在我们的项目中,我们正在升级诸如spring,hibernate等技术。我正在使用带有Hibernate 5.0.10的spring 4.3.11。我在整个项目中遇到了以下问题。
问题1:
Query query = (Query) getCurrentSession().createQuery("select SEQ_NEW.nextval from dual");
final List findByNamedQuery = query.list();
这句话正在抛出
java.lang.NoSuchMethodError: org.hibernate.Session.createQuery(Ljava/lang/String;)Lorg/hibernate/query/Query;
我在我的pojo中使用hibernate 5自动连接SessionFactory
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
@Repository
@Transactional
public class ServiceDAOTest {
@Autowired
protected SessionFactory sessionFactory;
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
protected Session getCurrentSession() {
return this.sessionFactory.openSession();
}
}
弹簧context.xml中
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManagerName" value="java:jboss/TransactionManager"/>
</bean>
<bean id="dataSource"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>DB_SRC_WFY</value>
</property>
</bean>
<tx:annotation-driven mode="proxy" transaction-manager="transactionManager" />
<bean id="TransDaoImpl"
class="com.services.transactionservice.dao.impl.TransDAOImpl">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource" />
</property>
<property name="mappingResources">
<list>
<value>Transaction.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.current_session_context_class">jta</prop>
<prop key="hibernate.transaction.jta.platform">org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform</prop>
<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</prop>
<prop key="hibernate.connection.release_mode">auto</prop>
<prop key="jta.UserTransaction">java:jboss/UserTransaction</prop>
</props>
</property>
</bean>
</beans>
问题2:
执行此方法时,
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Random;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobInstance;
import org.springframework.batch.core.JobParameter;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.JobParametersIncrementer;
import org.springframework.batch.core.configuration.JobLocator;
import org.springframework.batch.core.explore.JobExplorer;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.launch.JobParametersNotFoundException;
import org.springframework.scheduling.quartz.QuartzJobBean;
@DisallowConcurrentExecution
public class QuartzJobLauncher extends QuartzJobBean
{
private JobLauncher jobLauncher;
private JobLocator jobLocator;
private JobExplorer jobExplorer;
private Map<String, String> jobParameters;
public static final String JOB_NAME = "jobName";
@Override
@SuppressWarnings("unchecked")
protected void executeInternal(JobExecutionContext context) throws JobExecutionException
{
Map<String, Object> jobDataMap = context.getMergedJobDataMap();
String jobName = (String) jobDataMap.get(JOB_NAME);
try
{
//merged with ANID - start
log.debug("job name >>" + jobName);
Job job = null;
if (null != jobName)
{
job = jobLocator.getJob(jobName);
}
else
{
job = jobLocator.getJob("FaultRecovery");
}
//merged with ANID - end
JobParameters allParams = translateParams(job, jobParameters);
jobLauncher.run(job, allParams);
}
catch (Exception e)
{
log.error("Could not execute job.", e);
}
}
}
它抛出
java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session;
at org.springframework.batch.item.database.HibernateItemReaderHelper.createQuery(HibernateItemReaderHelper.java:152)
at org.springframework.batch.item.database.HibernateItemReaderHelper.readPage(HibernateItemReaderHelper.java:215)
at org.springframework.batch.item.database.HibernatePagingItemReader.doReadPage(HibernatePagingItemReader.java:167)
at org.springframework.batch.item.database.AbstractPagingItemReader.doRead(AbstractPagingItemReader.java:107)
at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.read(AbstractItemCountingItemStreamItemReader.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy93.read(Unknown Source)
at org.springframework.batch.core.step.item.SimpleChunkProvider.doRead(SimpleChunkProvider.java:90)
at org.springframework.batch.core.step.item.SimpleChunkProvider.read(SimpleChunkProvider.java:148)
at org.springframework.batch.core.step.item.SimpleChunkProvider$1.doInIteration(SimpleChunkProvider.java:108)
at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:367)
at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:214)
at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:143)
at org.springframework.batch.core.step.item.SimpleChunkProvider.provide(SimpleChunkProvider.java:103)
at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:68)
at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:371)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:262)
at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:76)
at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:367)
at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:214)
at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:143)
at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:248)
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:195)
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:135)
at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:61)
at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60)
at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:144)
at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:124)
at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:135)
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:281)
at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:120)
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:114)
at QuartzJobLauncher.executeInternal(QuartzJobLauncher.java:62)
at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:75)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
执行jobLauncher.run(job, allParams);
我认为这些问题彼此相关。当我经历类似的帖子时,他们正在使用带有hibernate 5.2的spring 4,他们指定使用hibernate 5.1或5.0。我正在使用hibernate 5.0,但我仍然遇到这些问题。
注意:这个确切的代码在spring 3和hibernate 3中正常运行。
这是来自wildfly 10的我的module.xml。
<?xml version="1.0" encoding="UTF-8"?>
<!-- ~ JBoss, Home of Professional Open Source. ~ Copyright 2011, Red Hat,
Inc., and individual contributors ~ as indicated by the @author tags. See
the copyright.txt file in the ~ distribution for a full listing of individual
contributors. ~ ~ This is free software; you can redistribute it and/or modify
it ~ under the terms of the GNU Lesser General Public License as ~ published
by the Free Software Foundation; either version 2.1 of ~ the License, or
(at your option) any later version. ~ ~ This software is distributed in the
hope that it will be useful, ~ but WITHOUT ANY WARRANTY; without even the
implied warranty of ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU ~ Lesser General Public License for more details. ~ ~ You should
have received a copy of the GNU Lesser General Public ~ License along with
this software; if not, write to the Free ~ Software Foundation, Inc., 51
Franklin St, Fifth Floor, Boston, MA ~ 02110-1301 USA, or see the FSF site:
http://www.fsf.org. -->
<module xmlns="urn:jboss:module:1.1" name="dependencies">
<dependencies>
<module name="javax.api" />
<!-- <module name="org.apache.ws.security" /> -->
<module name="javax.xml.bind.api" />
<module name="javax.xml.soap.api" />
<module name="javax.transaction.api" />
<module name="javax.persistence.api" export="true"/>
<module name="javax.servlet.api" />
<module name="javax.jms.api" />
<module name="javax.management.j2ee.api" export="true"/>
<module name="org.apache.log4j" />
<module name="sun.jdk" />
<module name="sqlserver.jdbc" />
<module name="com.unisys.leida.framework.services" />
<module name="com.unisys.leida.framework.runtime" />
<module name="com.unisys.leida.framework.lsb" />
</dependencies>
<resources>
<resource-root path="acegi-security-1.0.0.jar" />
<resource-root path="activation-1.1.jar" />
<resource-root path="antlr-2.7.6.jar" />
<resource-root path="antlr-3.3.jar" />
<resource-root path="antlr-runtime-3.4.jar" />
<resource-root path="aopalliance-1.0.jar" />
<resource-root path="aspectjrt-1.6.12.jar" />
<resource-root path="AssureID-1.0.jar" />
<resource-root path="activemq-client-5.10.2.jar" />
<resource-root path="aware-pivPack-jni-2.0.4.jar" />
<resource-root path="aware-preface-jni-4.0.1.jar" />
<resource-root path="aware-xm-1.3.2.jar" />
<resource-root path="axiom-api-1.2.9.jar" />
<resource-root path="axiom-impl-1.2.9.jar" />
<resource-root path="axis-1.0.jar" />
<resource-root path="batik-awt-util-1.6-1.jar"/>
<resource-root path="batik-bridge-1.6-1.jar"/>
<resource-root path="batik-css-1.6-1.jar"/>
<resource-root path="batik-dom-1.6-1.jar"/>
<resource-root path="batik-ext-1.6-1.jar"/>
<resource-root path="batik-gui-util-1.6-1.jar"/>
<resource-root path="batik-gvt-1.6-1.jar"/>
<resource-root path="batik-parser-1.6-1.jar"/>
<resource-root path="batik-script-1.6-1.jar"/>
<resource-root path="batik-svg-dom-1.6-1.jar"/>
<resource-root path="batik-util-1.6-1.jar"/>
<resource-root path="batik-xml-1.6-1.jar"/>
<resource-root path="barcode4j-2.0.jar"/>
<resource-root path="bcprov-jdk16-140.jar" />
<resource-root path="bsh-2.0b4.jar" />
<resource-root path="castor-1.3.jar" />
<resource-root path="ckez-1.0.jar" />
<resource-root path="comm-1.0.jar" />
<resource-root path="commons-codec-1.4.jar" />
<resource-root path="commons-collections-3.2.1.jar" />
<resource-root path="commons-collections-3.2.jar" />
<resource-root path="commons-compress-1.0.jar" />
<resource-root path="commons-dbcp-20030825.184428.jar" />
<resource-root path="commons-exec-1.0.1.jar" />
<resource-root path="commons-fileupload-1.0.jar" />
<resource-root path="commons-io-1.0.jar" />
<resource-root path="commons-io-2.4.jar" />
<resource-root path="commons-lang-2.4.jar" />
<resource-root path="commons-logging-1.1.jar" />
<resource-root path="commons-net-2.0.jar" />
<resource-root path="commons-pool-20030825.183949.jar" />
<resource-root path="commons-digester-1.7.jar" />
<resource-root path="commons-beanutils-1.8.0.jar" />
<resource-root path="dom4j-1.6.1.jar" />
<resource-root path="drools-compiler-5.3.1.Final.jar" />
<resource-root path="drools-core-5.3.1.Final.jar" />
<resource-root path="drools-persistence-jpa-5.3.1.Final.jar" />
<resource-root path="ecj-3.5.1.jar" />
<resource-root path="EPIBuilder_jni-1.0.jar" />
<resource-root path="ezjcom-1.8.jar" />
<resource-root path="fckez-1.0.jar" />
<resource-root path="Filters-1.0.jar" />
<resource-root path="flexjson-2.1.jar" />
<resource-root path="fmcojapi-1.3.jar" />
<resource-root path="Fraud_Schema-1.0.jar" />
<resource-root path="freemarker-2.3.15.jar" />
<resource-root path="geronimo-activation_1.1_spec-1.0.2.jar" />
<resource-root path="geronimo-javamail_1.4_spec-1.6.jar" />
<resource-root path="groovy-1.0.jar" />
<resource-root path="hibernate-commons-annotations-5.0.1.Final.jar" />
<resource-root path="hibernate-core-5.0.10.Final.jar" />
<resource-root path="hibernate-entitymanager-5.0.10.Final.jar" />
<resource-root path="hornetq-core-2.2.2.Final.jar" />
<resource-root path="icu4j-2.6.1.jar" />
<resource-root path="itext-2.1.7.jar" />
<resource-root path="jai_codec-1.0.jar" />
<resource-root path="jasperreports-4.0.1.jar" />
<resource-root path="jai_core-1.0.jar" />
<resource-root path="jai_imageio-1.0.jar" />
<resource-root path="JAssureIDCOMPlatformSDK-1.0.jar" />
<resource-root path="jasypt-1.9.1.jar" />
<resource-root path="javassist-3.10.0.GA.jar" />
<resource-root path="javassist-3.20.0-GA.jar" />
<resource-root path="jaxen-1.2.0-atlassian-2.jar" />
<!-- <resource-root path="jaxrpc-1.0.jar" /> -->
<resource-root path="jboss-seam-2.2.2.Final.jar" />
<!-- <resource-root path="jbpm-bam-5.5.0.Final.jar" /> -->
<resource-root path="jbpm-bpmn2-5.2.0.Final.jar" />
<resource-root path="jbpm-flow-5.2.0.Final.jar" />
<resource-root path="jbpm-flow-builder-5.2.0.Final.jar" />
<resource-root path="jbpm-human-task-5.2.0.Final.jar" />
<resource-root path="jbpm-jpdl-3.3.1.jar" />
<resource-root path="jbpm-persistence-jpa-5.2.0.Final.jar" />
<resource-root path="jbpm-workitems-5.2.0.Final.jar" />
<resource-root path="jdom-1.0.jar" />
<resource-root path="jnbcore-1.0.jar" />
<resource-root path="JPerson-1.0.jar" />
<resource-root path="junit-4.11.jar" />
<resource-root path="jython-1.0.jar" />
<resource-root path="knowledge-api-5.3.1.Final.jar" />
<resource-root path="L1ID_API-1.0.jar" />
<resource-root path="mail-1.4.jar" />
<resource-root path="milyn-smooks-all-1.4.jar" />
<resource-root path="mina-core-2.0.0-RC1.jar" />
<resource-root path="mvel2-2.1.RC1.jar" />
<resource-root path="opencsv-1.7.jar" />
<resource-root path="oro-2.0.8.jar" />
<resource-root path="PageScanApi-1.0.jar" />
<resource-root path="persistence-api-1.0.jar" />
<resource-root path="PtkSdk-1.0.jar" />
<resource-root path="rome-0.9.jar" />
<resource-root path="slf4j-api-1.6.1.jar" />
<resource-root path="slf4j-log4j12-1.6.1.jar" />
<resource-root path="smack-3.0.4.jar" />
<resource-root path="spring-aop-4.3.11.RELEASE.jar" />
<resource-root path="spring-batch-admin-manager-1.2.0.RELEASE.jar" />
<resource-root path="spring-batch-admin-resources-1.2.0.RELEASE.jar" />
<resource-root path="spring-batch-core-2.1.5.RELEASE.jar" />
<resource-root path="spring-batch-infrastructure-2.1.5.RELEASE.jar" />
<resource-root path="spring-batch-integration-1.2.0.RELEASE.jar" />
<resource-root path="spring-batch-test-2.1.5.RELEASE.jar" />
<resource-root path="spring-beans-4.3.11.RELEASE.jar" /> <!-- pavan -->
<resource-root path="spring-context-4.3.11.RELEASE.jar" />
<resource-root path="spring-context-support-4.3.11.RELEASE.jar" />
<resource-root path="spring-core-4.3.11.RELEASE.jar" />
<resource-root path="spring-expression-4.3.11.RELEASE.jar" />
<resource-root path="spring-integration-core-4.3.12.RELEASE.jar" />
<resource-root path="spring-integration-file-4.3.12.RELEASE.jar" />
<resource-root path="spring-integration-ftp-4.3.12.RELEASE.jar" />
<resource-root path="spring-integration-http-4.3.12.RELEASE.jar" />
<resource-root path="spring-integration-jms-4.3.12.RELEASE.jar" />
<resource-root path="spring-integration-jmx-4.3.12.RELEASE.jar" />
<resource-root path="spring-integration-mail-4.3.12.RELEASE.jar" />
<resource-root path="spring-messaging-4.3.11.RELEASE.jar" />
<resource-root path="spring-retry-1.2.1.RELEASE.jar" />
<resource-root path="spring-jdbc-4.3.11.RELEASE.jar" />
<resource-root path="spring-jms-4.3.11.RELEASE.jar" />
<resource-root path="spring-ldap-core-1.3.1.RELEASE.jar" />
<resource-root path="spring-mock-2.0.8.jar" />
<resource-root path="spring-orm-4.2.6.RELEASE.jar" />
<resource-root path="spring-oxm-4.3.11.RELEASE.jar" />
<resource-root path="spring-remoting-2.0-m2.jar" />
<resource-root path="spring-security-core-4.2.3.RELEASE.jar" />
<resource-root path="spring-security-crypto-4.2.3.RELEASE.jar" />
<resource-root path="spring-security-ldap-4.2.3.RELEASE.jar" />
<resource-root path="spring-support-2.0-m2.jar" />
<resource-root path="spring-tx-4.3.11.RELEASE.jar" />
<resource-root path="spring-web-4.3.11.RELEASE.jar" />
<resource-root path="spring-webmvc-4.3.11.RELEASE.jar" />
<resource-root path="spring-ws-2.0.4.RELEASE.jar" />
<resource-root path="spring-ws-core-2.0.4.RELEASE.jar" />
<resource-root path="spring-xml-2.0.4.RELEASE.jar" />
<resource-root path="sqljdbc4-3.0.jar" />
<resource-root path="stringtemplate-3.2.jar" />
<resource-root path="WSQUtil-1.0.jar" />
<resource-root path="wss4j-1.5.8.jar" />
<resource-root path="xdb-6.jar" />
<resource-root path="xercesImpl-2.6.2.jar" />
<resource-root path="xmlpull-1.1.3.1.jar" />
<resource-root path="xmlsec-1.4.3.jar" />
<resource-root path="xmlsec-2.0.jar" />
<resource-root path="xom-1.0.jar" />
<resource-root path="xstream-1.3.1.jar" />
<resource-root path="zcommon-6.5.2.jar" />
<resource-root path="zel-6.5.2.jar" />
<resource-root path="zhtml-6.5.2.jar" />
<resource-root path="zk-6.5.2.jar" />
<resource-root path="zkbind-6.5.2.jar" />
<resource-root path="zkplus-6.5.2.jar" />
<resource-root path="zul-6.5.2.jar" />
<resource-root path="zweb-6.5.2.jar" />
<resource-root path="zweb-6.5.2.jar" />
<resource-root path="json-simple-1.1.1.jar" />
<resource-root path="commons-httpclient-3.1.jar" />
<resource-root path="jbossts-common-jbossts-common.jar" />
<resource-root path="jbossjta-4.2.2.GA.jar" />
<resource-root path="concurrent-1.3.4.jar" />
<resource-root path="cglib-2.2.jar" />
<resource-root path="jettison-1.1.jar" />
<resource-root path="quartz-2.2.1.jar" />
<resource-root path="jboss-logging-3.3.0.Final.jar" />
<resource-root path="classmate-1.3.0.jar" />
<resource-root path="jasypt-hibernate5-1.9.3-SNAPSHOT.jar" />
<resource-root path="hibernate-infinispan-5.0.10.Final.jar" />
<resource-root path="xmlbeans-2.5.0.jar" />
</resources>
</module>
答案 0 :(得分:0)
终于解决了问题! 事实证明我正在构建hibernate 5.2.x上的代码,在运行时我降级了它。一旦我用hibernate 5.0.10重建它就可以了。