Je suis nouveau sur Java EE et quand j'essaie de récupérer des données de la base HSQL via JPA j'obtient les erreurs suivantes dans ma console Widlfy :
Class Club :
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 20:11:53,780 INFO [stdout] (default task-12) Hibernate: select club0_.id as id1_2_, club0_.league_id as league_i4_2_, club0_.name as name2_2_, club0_.nbTitles as nbTitles3_2_ from "Club" club0_ 20:11:53,785 WARN [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-12) SQL Error: 42102, SQLState: 42S02 20:11:53,785 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-12) Table "Club" not found; SQL statement: select club0_.id as id1_2_, club0_.league_id as league_i4_2_, club0_.name as name2_2_, club0_.nbTitles as nbTitles3_2_ from "Club" club0_ [42102-173] 20:11:53,787 ERROR [org.jboss.as.ejb3.invocation] (default task-12) JBAS014134: EJB Invocation failed on component FootballBean for method public abstract java.util.List ch.hevs.footballservice.Football.getClubs(): javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not prepare statement !!!!!! DELETED LINES !!!!!! !!!!!! DELETED LINES !!!!!! Caused by: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not prepare statement !!!!!! DELETED LINES !!!!!! !!!!!! DELETED LINES !!!!!! Caused by: org.hibernate.exception.SQLGrammarException: could not prepare statement !!!!!! DELETED LINES !!!!!! !!!!!! DELETED LINES !!!!!! Caused by: org.h2.jdbc.JdbcSQLException: Table "Club" not found; SQL statement: select club0_.id as id1_2_, club0_.league_id as league_i4_2_, club0_.name as name2_2_, club0_.nbTitles as nbTitles3_2_ from "Club" club0_ [42102-173] !!!!!! DELETED LINES !!!!!! !!!!!! DELETED LINES !!!!!!
Persistence.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71 import java.util.List; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; @Entity @Table(name="`Club`") public class Club { // attributs @Id @GeneratedValue(strategy = GenerationType.SEQUENCE) private Long id; private String name; private int nbTitles; // relations @OneToMany(mappedBy = "club") private List<Player> players; @ManyToOne private League league; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getNbTitles() { return nbTitles; } public void setNbTitles(int nbTitles) { this.nbTitles = nbTitles; } public List<Player> getPlayers() { return players; } public void setPlayers(List<Player> players) { this.players = players; } public League getLeague() { return league; } public void setLeague(League league) { this.league = league; } // constructors public Club() { } }
J'ai créé ma base de données avec le test JUnit suivant :
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 <?xml version="1.0" encoding="UTF-8"?> <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0"> <persistence-unit name="footballPU"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <class>ch.hevs.businessobject.Club</class> <class>ch.hevs.businessobject.League</class> <class>ch.hevs.businessobject.Player</class> <properties> <property name="hibernate.connection.url" value="jdbc:hsqldb:hsql://localhost/DB" /> <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver" /> <property name="hibernate.connection.username" value="sa" /> <property name="hibernate.connection.password" value="" /> <property name="hibernate.show_sql" value="true" /> </properties> </persistence-unit> </persistence>
Quand j'exécute la requête suivant générée par l'EntityManager dans mon HSQL DATABASE manager, la requête fonctionne..
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 import junit.framework.TestCase; import org.hibernate.cfg.Configuration; import org.hibernate.tool.hbm2ddl.SchemaExport; import org.junit.Test; public class CreateSchemaTest extends TestCase { @Test public void test() { Configuration cfg = new Configuration(); cfg.addAnnotatedClass(ch.hevs.businessobject.Player.class); cfg.addAnnotatedClass(ch.hevs.businessobject.Club.class); cfg.addAnnotatedClass(ch.hevs.businessobject.League.class); cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect"); cfg.setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver"); cfg.setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver"); cfg.setProperty("hibernate.connection.url", "jdbc:hsqldb:hsql://localhost/DB"); cfg.setProperty("hibernate.connection.username", "sa"); new SchemaExport(cfg).setOutputFile("schema.ddl").create(false, true); } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part select club0_.id as id1_2_, club0_.league_id as league_i4_2_, club0_.name as name2_2_, club0_.nbTitles as nbTitles3_2_ from "Club" club0_
Est-ce que quelqu'un aurait une idée ?
Salutations
Partager