Bonjour à tous,
J'essaye actuellement d'exécuter des procédures ou des functions stockées sous oracle depuis un programme Java en utilisant les annotations liées à Oracle.
Voici mon fichier de persistance:
Voici l'entity:
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 <?xml version="1.0" encoding="UTF-8"?> <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> <persistence-unit name="mnf-pu" transaction-type="RESOURCE_LOCAL"> <properties> <!-- Configuring JDBC properties --> <property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:@strldevebdb:1529/DSEB01" /> <property name="javax.persistence.jdbc.user" value="STREAMLINE_HRMATEP" /> <property name="javax.persistence.jdbc.password" value="lkmds984!" /> <property name="javax.persistence.jdbc.driver" value="oracle.jdbc.driver.OracleDriver" /> <!-- Hibernate properties --> <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" /> <property name="hibernate.synonyms" value="true"/> <property name="hibernate.show_sql" value="true" /> <property name="hibernate.connection.shutdown" value="true" /> </properties> </persistence-unit> </persistence>
Voici le fichier de test CopyOfApp :
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
72
73
74
75
76
77 package com.memorynotfound.hibernate; import javax.persistence.Column; import javax.persistence.Embeddable; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import org.eclipse.persistence.annotations.Struct; import org.eclipse.persistence.platform.database.oracle.annotations.NamedPLSQLStoredFunctionQuery; import org.eclipse.persistence.platform.database.oracle.annotations.PLSQLParameter; import org.eclipse.persistence.platform.database.oracle.annotations.PLSQLRecord; @NamedPLSQLStoredFunctionQuery( name = "getCopyOfBook", functionName = "MYPACKAGE.GET_BOOK", returnParameter = @PLSQLParameter( name="RESULT", databaseType="MYPACKAGE.BOOK_REC")) @Embeddable @Struct( name = "BOOK_TYPE", fields={"ID", "TITLE"}) @PLSQLRecord( name = "MYPACKAGE.BOOK_REC", compatibleType = "BOOK_TYPE", javaType = CopyOfBook.class, fields = { @PLSQLParameter( name="ID", databaseType="NUMERIC_TYPE"), @PLSQLParameter( name="TITLE") } ) public class CopyOfBook { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name="ID") private Integer id; @Column(name="TITLE") private String title; public CopyOfBook() { } public CopyOfBook(String title) { this.title = title; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } @Override public String toString() { return "Book{" + "id=" + id + ", title='" + title + '\'' + '}'; } }
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 package com.memorynotfound.hibernate; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence; import javax.persistence.Query; public class CopyOfApp { public static void main (String...args) throws InterruptedException { EntityManagerFactory emf = Persistence.createEntityManagerFactory("mnf-pu"); EntityManager em = emf.createEntityManager(); Query query = em.createNamedQuery("getCopyOfBook"); CopyOfBook result = (CopyOfBook)query.getSingleResult(); System.out.println(result.getTitle()); em.close(); emf.close(); } }
Et éventuellement le pom
Lors de l'exécution de CopyOfApp j'obtiens l'erreur suivante:
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 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.memorynotfound.db.hibernate</groupId> <artifactId>named-stored-procedure</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>war</packaging> <name>HIBERNATE - ${project.artifactId}</name> <url>http://memorynotfound.com</url> <properties> <mysql.driver.version>5.1.9</mysql.driver.version> <hibernate.version>4.3.1.Final</hibernate.version> </properties> <dependencies> <!-- dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>${mysql.driver.version}</version> </dependency--> <dependency> <groupId>oracle.jdbc</groupId> <artifactId>ojdbc6</artifactId> <version>11.2.0.4.0</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>${hibernate.version}</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> <version>${hibernate.version}</version> </dependency> <dependency> <groupId>org.glassfish.extras</groupId> <artifactId>glassfish-embedded-web</artifactId> <version>3.1.1-b11</version> </dependency> </dependencies> <build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.5.1</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> </plugins> </build> </project>
Merci d'avance pour votre aide.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 Feb 27, 2017 2:57:48 PM org.hibernate.validator.engine.resolver.DefaultTraversableResolver detectJPA INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver. Exception in thread "main" java.lang.IllegalArgumentException: No query defined for that name [getCopyOfBook] at org.hibernate.jpa.spi.AbstractEntityManagerImpl.buildQueryFromName(AbstractEntityManagerImpl.java:788) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.createNamedQuery(AbstractEntityManagerImpl.java:767) at com.memorynotfound.hibernate.CopyOfApp.main(CopyOfApp.java:15)
Partager