Bonsoire,
Je suis débutant en programmation avec spring Data et la spécification JPA.
tout est bien mais lorsque j'ajoute ce ligne de code :[CODE]itemRepository.save(item1); [CODE] dans la maethode init() du classe InitDbService.java, j'ai eu cette erreur et je n'ai pas compris pourquoi il n'y a pas trouvé l'objet Item.
la classe InitDbService.java
Elle permet juste d'initialiser la base des données après le démarrage du conteneur web jetty.Comme je vous dit tout est bien , pas d'exeption avant l'ajout du ligne
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 @Transactional @Service public class InitDbService { @Autowired private RoleRepository roleRepository; @Autowired private UserRepository userRepository; @Autowired private ItemRepository itemRepository; @Autowired private BlogRepository blogRepository; @PostConstruct public void init() { Role roleUser = new Role(); roleUser.setName("ROLE_USER"); roleRepository.save(roleUser); Role roleAdmin = new Role(); roleAdmin.setName("ROLE_ADMIN"); roleRepository.save(roleAdmin); User userAdmin = new User(); userAdmin.setName("admin"); List<Role> roles = new ArrayList<Role>(); roles.add(roleUser); roles.add(roleAdmin); userAdmin.setRoles(roles); userRepository.save(userAdmin); Blog blogJavaVids = new Blog(); blogJavaVids.setName("JavaVids"); blogJavaVids.setUrl("http://feeds.feedburner.com/javavids?format=xml"); blogJavaVids.setUser(userAdmin); blogRepository.save(blogJavaVids); Item item1 = new Item(); item1.setBlog(blogJavaVids); item1.setTitle("first"); item1.setLink("http://www.javavids.com"); item1.setPublishedDate(new Date()); itemRepository.save(item1); } }le fichier applicationContext.xml
Code : Sélectionner tout - Visualiser dans une fenêtre à part itemRepository.save(item1);
et le fichier dispatcherServlet.xml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 <?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:context="http://www.springframework.org/schema/context" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"> <context:component-scan base-package="cz.jiripinkas.jba"> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /> </context:component-scan> <jdbc:embedded-database type="HSQL" id="dataSource" /> <bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="packagesToScan" value="cz.jiripinkas.jba.entity" /> <property name="dataSource" ref="dataSource" /> <property name="jpaProperties"> <props> <prop key="hibernate.show_sql"> true</prop> <prop key="hibernate.hbm2ddl.auto"> create</prop> </props> </property> <property name="persistenceProvider"> <bean class="org.hibernate.jpa.HibernatePersistenceProvider" /> </property> </bean> <jpa:repositories base-package="cz.jiripinkas.jba.repository" entity-manager-factory-ref="emf" transaction-manager-ref="transactionManager" /> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <tx:annotation-driven transaction-manager="transactionManager" /> </beans>
et je vous donne l'erreur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 <?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:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"> <context:component-scan base-package="cz.jiripinkas.jba.controller" /> <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer"> <property name="definitions"> <list> <value>/WEB-INF/defs/general.xml</value> </list> </property> </bean> <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView" /> </bean> </beans>
Merci.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 Error creating bean with name 'initDbService': Invocation of init method failed Caused by: org.springframework.orm.jpa.JpaSystemException: org.hibernate.exception.SQLGrammarException: could not prepare statement Caused by: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not prepare statement Caused by: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not prepare statement Caused by: org.hsqldb.HsqlException: user lacks privilege or object not found: ITEM
Partager