Advertisement
Guest User

Untitled

a guest
Aug 15th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.29 KB | None | 0 0
  1. Caused by: java.lang.ClassNotFoundException: org.hibernate.ejb.HibernatePersistence
  2. at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
  3. at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
  4. at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
  5. at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
  6. ... 51 more
  7.  
  8. Caused by: java.lang.NoClassDefFoundError: org/hibernate/ejb/HibernatePersistence
  9. at org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter.<init>(HibernateJpaVendorAdapter.java:57)
  10. at com.edf.fr.batch.MarcheBatchConfiguration.jpaVendorAdapter(MarcheBatchConfiguration.java:204)
  11. at com.edf.fr.batch.MarcheBatchConfiguration$$EnhancerBySpringCGLIB$$89ce9a5b.CGLIB$jpaVendorAdapter$6(<generated>)
  12. at com.edf.fr.batch.MarcheBatchConfiguration$$EnhancerBySpringCGLIB$$89ce9a5b$$FastClassBySpringCGLIB$$d4b1171.invoke(<generated>)
  13. at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
  14. at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309)
  15. at com.edf.fr.batch.MarcheBatchConfiguration$$EnhancerBySpringCGLIB$$89ce9a5b.jpaVendorAdapter(<generated>)
  16. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  17. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  18. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  19. at java.lang.reflect.Method.invoke(Method.java:497)
  20. at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
  21. ... 39 more
  22.  
  23. package com.edf.fr.batch;
  24.  
  25. import java.sql.SQLException;
  26. import java.util.Properties;
  27.  
  28. import javax.sql.DataSource;
  29.  
  30. import org.springframework.batch.core.Job;
  31. import org.springframework.batch.core.Step;
  32. import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
  33. import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
  34. import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
  35. import org.springframework.batch.core.launch.support.RunIdIncrementer;
  36. import org.springframework.batch.item.ItemProcessor;
  37. import org.springframework.batch.item.ItemReader;
  38. import org.springframework.batch.item.ItemWriter;
  39. import org.springframework.batch.item.database.JpaItemWriter;
  40. import org.springframework.batch.item.file.FlatFileItemReader;
  41. import org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper;
  42. import org.springframework.batch.item.file.mapping.DefaultLineMapper;
  43. import org.springframework.batch.item.file.transform.DelimitedLineTokenizer;
  44. import org.springframework.batch.test.JobLauncherTestUtils;
  45. import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
  46. import org.springframework.context.annotation.Bean;
  47. import org.springframework.context.annotation.ComponentScan;
  48. import org.springframework.context.annotation.Configuration;
  49. import org.springframework.core.io.ClassPathResource;
  50. import org.springframework.jdbc.core.JdbcTemplate;
  51. import org.springframework.jdbc.datasource.DriverManagerDataSource;
  52. import org.springframework.orm.jpa.JpaVendorAdapter;
  53. import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
  54. import org.springframework.orm.jpa.vendor.Database;
  55. import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
  56.  
  57. /**
  58. * This class contains all the configuration of the Spring Batch application
  59. * used for this tutorial. It contains readers, writers, processors, jobs, steps
  60. * and all the needed beans.
  61. * @author dgutierrez-diez
  62. */
  63. @Configuration
  64. @EnableBatchProcessing
  65. @ComponentScan
  66. @EnableAutoConfiguration
  67. public class MarcheBatchConfiguration {
  68.  
  69. /**
  70. * Modes, should be injected as parameter TODO
  71. */
  72.  
  73. /*
  74. * ********************************************
  75. * READERS This section contains all the readers
  76. * ********************************************
  77. */
  78.  
  79. /**
  80. * @return a reader
  81. */
  82.  
  83. @Bean
  84. public ItemReader<CustomPojo> reader() {
  85.  
  86. System.out.println("Inside item reader");
  87. // flat file item reader (using an csv extractor)
  88. FlatFileItemReader<CustomPojo> reader = new FlatFileItemReader<CustomPojo>();
  89. reader.setResource(new ClassPathResource("input.csv"));
  90. reader.setLineMapper(new DefaultLineMapper<CustomPojo>() {
  91. {
  92. setLineTokenizer(new DelimitedLineTokenizer() {
  93. {
  94. setNames(new String[] { "id", "description" });
  95. }
  96. });
  97. setFieldSetMapper(new BeanWrapperFieldSetMapper<CustomPojo>() {
  98. {
  99. setTargetType(CustomPojo.class);
  100. }
  101. });
  102. }
  103. });
  104. return reader;
  105. }
  106.  
  107. /*
  108. * ********************************************
  109. * PROCESSORS This section contains all processors
  110. * ********************************************
  111. */
  112.  
  113. /**
  114. * @return custom item processor -> anything
  115. */
  116. @Bean
  117. public ItemProcessor<CustomPojo, CustomPojo> processor() {
  118. return new CustomItemProcessor();
  119. }
  120.  
  121. /*
  122. * ********************************************
  123. * WRITERS This section contains all the writers
  124. * ********************************************
  125. */
  126.  
  127. /**
  128. * @param dataSource
  129. * @return dummy item writer custom
  130. * @throws SQLException
  131. */
  132. @Bean
  133. public ItemWriter<CustomPojo> writer(DataSource dataSource) throws SQLException {
  134. System.out.println("Inside item writer");
  135.  
  136. /*
  137. * JdbcBatchItemWriter<CustomPojo> writer = new JdbcBatchItemWriter<CustomPojo>();
  138. * writer.setSql("INSERT INTO pojocheck (id, description) VALUES (:id, :description)");
  139. * writer.setDataSource(dataSource);
  140. * writer.setItemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<CustomPojo>());
  141. */
  142. JpaItemWriter<CustomPojo> writer = new JpaItemWriter<CustomPojo>();
  143. writer.setEntityManagerFactory(entityManagerFactory().getObject());
  144. return writer;
  145. }
  146.  
  147. /*
  148. * ********************************************
  149. * JOBS ***************************************
  150. * ********************************************
  151. */
  152. /**
  153. * @param jobs
  154. * @param s1
  155. * steps
  156. * @return the Job
  157. */
  158. @Bean
  159. public Job importUserJob(JobBuilderFactory jobs, Step s1) {
  160. return jobs.get("importUserJob").incrementer(new RunIdIncrementer()).flow(s1).end().build();
  161. }
  162.  
  163. /*
  164. * ********************************************
  165. * STEPS **************************************
  166. * ********************************************
  167. */
  168.  
  169. /**
  170. * the step 1 contains a reader a processor and a writer using a chunk of 10
  171. * @param stepBuilderFactory
  172. * @param reader
  173. * @param writer
  174. * @param processor
  175. * @return
  176. */
  177. @Bean
  178. public Step step1(StepBuilderFactory stepBuilderFactory, ItemReader<CustomPojo> reader,
  179. ItemWriter<CustomPojo> writer, ItemProcessor<CustomPojo, CustomPojo> processor) {
  180. /* it handles bunches of 10 units */
  181. return stepBuilderFactory.get("step1").<CustomPojo, CustomPojo> chunk(10).reader(reader)
  182. .processor(processor).writer(writer).build();
  183. }
  184.  
  185. /*
  186. * ********************************************
  187. * UTILITY BEANS ******************************
  188. * ********************************************
  189. */
  190.  
  191. /**
  192. * jdbc template (hsqldb)
  193. * @param dataSource
  194. * @return JdbcTemplate
  195. */
  196. @Bean
  197. public JdbcTemplate jdbcTemplate(DataSource dataSource) {
  198. return new JdbcTemplate(dataSource);
  199. }
  200.  
  201. @Bean
  202. public DataSource dataSource() throws SQLException {
  203.  
  204. final DriverManagerDataSource dataSource = new DriverManagerDataSource();
  205. dataSource.setDriverClassName("org.postgresql.Driver");
  206. dataSource.setUrl("jdbc:postgresql://localhost:5432/engc_local");
  207. dataSource.setUsername("postgres");
  208. dataSource.setPassword("postgres");
  209. return dataSource;
  210.  
  211. }
  212.  
  213. @Bean
  214. public LocalContainerEntityManagerFactoryBean entityManagerFactory() throws SQLException {
  215.  
  216. LocalContainerEntityManagerFactoryBean lef = new LocalContainerEntityManagerFactoryBean();
  217. lef.setDataSource(dataSource());
  218. lef.setJpaVendorAdapter(jpaVendorAdapter());
  219. lef.setJpaProperties(new Properties());
  220. lef.setPackagesToScan("com.edf.fr");
  221. return lef;
  222. }
  223.  
  224. @Bean
  225. public JpaVendorAdapter jpaVendorAdapter() {
  226. HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
  227. jpaVendorAdapter.setDatabase(Database.POSTGRESQL);
  228. jpaVendorAdapter.setGenerateDdl(true);
  229. jpaVendorAdapter.setShowSql(true);
  230. jpaVendorAdapter.setDatabasePlatform("org.hibernate.dialect.PostgreSQLDialect");
  231. return jpaVendorAdapter;
  232. }
  233.  
  234. /**
  235. * jobLauncherTestUtils utility class for testing batches
  236. * @return JobLauncherTestUtils
  237. */
  238. @Bean
  239. public JobLauncherTestUtils jobLauncherTestUtils() {
  240. return new JobLauncherTestUtils();
  241. }
  242.  
  243. }
  244.  
  245. package com.edf.fr.batch;
  246.  
  247. import javax.persistence.Column;
  248. import javax.persistence.Entity;
  249. import javax.persistence.GeneratedValue;
  250. import javax.persistence.Id;
  251. import javax.persistence.Table;
  252.  
  253. @Entity
  254. @Table(name = "Marche")
  255. public class CustomPojo {
  256. @Id
  257. @Column
  258. @GeneratedValue
  259. private String id;
  260.  
  261. @Column
  262. private String description;
  263.  
  264. public CustomPojo() {
  265.  
  266. }
  267.  
  268. public CustomPojo(String id, String description) {
  269. this.id = id;
  270. this.description = description;
  271. }
  272.  
  273. @Override
  274. public String toString() {
  275. return id + "," + description;
  276. }
  277.  
  278. public String getId() {
  279. return id;
  280. }
  281.  
  282. public void setId(String id) {
  283. this.id = id;
  284. }
  285.  
  286. public String getDescription() {
  287. return description;
  288. }
  289.  
  290. public void setDescription(String description) {
  291. this.description = description;
  292. }
  293.  
  294. }
  295.  
  296. <?xml version="1.0" encoding="UTF-8"?>
  297. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  298. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  299. <modelVersion>4.0.0</modelVersion>
  300.  
  301. <groupId>com.edf.fr.batch</groupId>
  302. <artifactId>edf-marche-batch</artifactId>
  303. <version>0.1.0</version>
  304.  
  305. <parent>
  306. <groupId>org.springframework.boot</groupId>
  307. <artifactId>spring-boot-starter-parent</artifactId>
  308. <version>1.2.1.RELEASE</version>
  309. </parent>
  310.  
  311. <dependencies>
  312. <dependency>
  313. <groupId>org.springframework.boot</groupId>
  314. <artifactId>spring-boot-starter-batch</artifactId>
  315. </dependency>
  316. <dependency>
  317. <groupId>org.hsqldb</groupId>
  318. <artifactId>hsqldb</artifactId>
  319. </dependency>
  320. <dependency>
  321. <groupId>mysql</groupId>
  322. <artifactId>mysql-connector-java</artifactId>
  323. </dependency>
  324. <!-- Spring Batch unit test -->
  325. <dependency>
  326. <groupId>org.springframework.batch</groupId>
  327. <artifactId>spring-batch-test</artifactId>
  328. </dependency>
  329. <dependency>
  330. <groupId>postgresql</groupId>
  331. <artifactId>postgresql</artifactId>
  332. <version>9.1-901-1.jdbc4</version>
  333. </dependency>
  334. <dependency>
  335. <groupId>org.hibernate</groupId>
  336. <artifactId>hibernate-entitymanager</artifactId>
  337. <version>5.2.10.Final</version><!--$NO-MVN-MAN-VER$-->
  338. </dependency>
  339. <dependency>
  340. <groupId>org.springframework</groupId>
  341. <artifactId>spring-orm</artifactId>
  342. <version>3.1.1.RELEASE</version><!--$NO-MVN-MAN-VER$-->
  343. </dependency>
  344.  
  345. <!-- Junit -->
  346. <dependency>
  347. <groupId>junit</groupId>
  348. <artifactId>junit</artifactId>
  349. <scope>test</scope>
  350. </dependency>
  351. </dependencies>
  352.  
  353.  
  354.  
  355. <build>
  356. <plugins>
  357. <plugin>
  358. <groupId>org.springframework.boot</groupId>
  359. <artifactId>spring-boot-maven-plugin</artifactId>
  360. </plugin>
  361. </plugins>
  362. </build>
  363. </project>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement