編集:休止状態はこれを自動的に実行できるはずですが、必要な構造を含むDDLスクリプトがあります。hibernateが自動的にテーブルを作成するようにこのスクリプトを実行できれば、今のところ満足しています...`この質問を参照してください
長い投稿の言い訳。私の質問は非常に単純かもしれませんが、休止状態で春の初心者なので、これは今朝ずっと私を悩ませています...。
SpringBatchを使用しています。インポートジョブを実行するとき、Springはジョブの実行に関するメタデータをBATCH_JOBという名前のテーブルに格納したいと考えています。ただし、このテーブルはHibernateによって作成されたものではありません。
私は次の方法でジョブを実行します。
public static void main(String[] args) throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException {
ApplicationContext context = new ClassPathXmlApplicationContext("bean_configuration.xml");
SimpleJobLauncher launcher = (SimpleJobLauncher) context.getBean("jobLauncher");
FlowJob job = (FlowJob) context.getBean("importIVSJob");
launcher.run(job, new JobParameters());
}
私の休止状態のプロパティファイル:
#hibernate.c3p0.min_size=5
#hibernate.c3p0.max_size=20
#hibernate.c3p0.timeout=1800
#hibernate.c3p0.max_statements=50
hibernate.dialect=org.hibernate.dialect.HSQLDialect
hibernate.show_sql=true
hibernate.hbm2ddl.auto=create
およびxml構成:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/batch
http://www.springframework.org/schema/batch/spring-batch-2.1.xsd">
<batch:job job-repository="jobRepository" id="importIVSJob">
<batch:step id="step1">
<batch:tasklet transaction-manager="transactionManager">
<batch:chunk reader="csvFileReader" writer="itemWriter"
commit-interval="5" />
</batch:tasklet>
</batch:step>
</batch:job>
<bean id="csvFileReader" class="org.springframework.batch.item.file.FlatFileItemReader">
<property name="resource" ref="inputResource" />
<property name="lineMapper">
<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
<property name="lineTokenizer">
<bean
class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer"
p:delimiter=";"
p:names="objectcode, event, beginTijd, duurEvent, kolkNummer, deelkolkNummer, vaarrichting, eniNummer, aantalSchepen, scheepType, vaartType, subTypeVaart, rwsKlasseHoofgroep, rwsKlasseSubgroep, cemtKlasse, laadvermogen, dwtLaadvermogen, scheepslengte, scheepsbreedte, scheepsdiepgang, scheepshoogte, vlagCode, beladingsCode, cargoGewicht, seinVoeringKegel, vrachtAanBoord, aantalContainers, aantalTEU_containers, reisId, toerbeurt, invaartGroen, uitvaartGroen" />
</property>
<property name="fieldSetMapper">
<bean
class="org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper"
p:targetType="nl.triopsys.styx.importeer.IVS.IvsBericht" />
</property>
</bean>
</property>
</bean>
<bean id="itemWriter" class="org.springframework.batch.item.file.FlatFileItemWriter">
<property name="resource" ref="outputResource" />
<property name="lineAggregator">
<bean
class="org.springframework.batch.item.file.transform.DelimitedLineAggregator">
<property name="delimiter" value="," />
<property name="fieldExtractor">
<bean
class="org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor">
<property name="names"
value="objectcode, event, beginTijd, duurEvent, kolkNummer, deelkolkNummer, vaarrichting, eniNummer, aantalSchepen, scheepType, vaartType, subTypeVaart, rwsKlasseHoofgroep, rwsKlasseSubgroep, cemtKlasse, laadvermogen, dwtLaadvermogen, scheepslengte, scheepsbreedte, scheepsdiepgang, scheepshoogte, vlagCode, beladingsCode, cargoGewicht, seinVoeringKegel, vrachtAanBoord, aantalContainers, aantalTEU_containers, reisId, toerbeurt, invaartGroen, uitvaartGroen" />
</bean>
</property>
</bean>
</property>
</bean>
<bean id="inputResource" class="org.springframework.core.io.FileSystemResource">
<constructor-arg index="0" value="file:C:\Users\jgoddijn\testdata\IVS90.csv" />
</bean>
<bean id="outputResource" class="org.springframework.core.io.FileSystemResource">
<constructor-arg index="0" value="C:\Users\jgoddijn\testdata\output.csv" />
</bean>
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="batch.properties" p:ignoreUnresolvablePlaceholders="true" />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
<property name="url"
value="jdbc:hsqldb:file:/D:/DMVV/HSQLDB;shutdown=true;hsqldb.write_delay=false" />
<property name="username" value="sa" />
<property name="password" value="" />
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>nl.triopsys.styx.importeer.IVS.IvsBericht</value>
<value>nl.triopsys.styx.domain.Vaartuig</value>
<value>nl.triopsys.styx.domain.AIS.MMSI</value>
<value>nl.triopsys.styx.domain.IVS90.valuetype.Scheepsnummer</value>
<value>nl.triopsys.styx.domain.IVS90.valuetype.EniNummer</value>
<value>nl.triopsys.styx.domain.IVS90.valuetype.ImoNummer</value>
</list>
</property>
<property name="hibernateProperties">
<bean
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="location" value="batch.properties" />
</bean>
</property>
</bean>
<bean id="jobRegistry"
class="org.springframework.batch.core.configuration.support.MapJobRegistry" />
<bean id="jobLauncher"
class="org.springframework.batch.core.launch.support.SimpleJobLauncher"
p:jobRepository-ref="jobRepository" />
<bean id="jobRegistryBeanPostProcessor"
class="org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor"
p:jobRegistry-ref="jobRegistry" />
<bean id="jobRepository"
class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean"
p:dataSource-ref="dataSource" p:transactionManager-ref="transactionManager" />
</beans>
そして私が得るエラー:
Exception in thread "main" org.hibernate.exception.SQLGrammarException: user lacks privilege or object not found: BATCH_JOB_INSTANCE
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:83)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
at org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler.continueInvocation(ConnectionProxyHandler.java:146)
at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
at $Proxy20.prepareStatement(Unknown Source)
at org.springframework.jdbc.core.JdbcTemplate$SimplePreparedStatementCreator.createPreparedStatement(JdbcTemplate.java:1436)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:581)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:637)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:666)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:674)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:714)
at org.springframework.jdbc.core.simple.SimpleJdbcTemplate.query(SimpleJdbcTemplate.java:204)
at org.springframework.jdbc.core.simple.SimpleJdbcTemplate.query(SimpleJdbcTemplate.java:209)
at org.springframework.batch.core.repository.dao.JdbcJobInstanceDao.getJobInstance(JdbcJobInstanceDao.java:221)
at org.springframework.batch.core.repository.support.SimpleJobRepository.getLastJobExecution(SimpleJobRepository.java:253)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy19.getLastJobExecution(Unknown Source)
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:94)
at nl.triopsys.styx.sandbox.importeer.RunImport.main(RunImport.java:39)
ジョブ実行用のテーブルが作成されていないようです。これを自動的に行うために休止状態にする方法は?
ありがとうございました!