Bonjour,
Je dois faire un projet en J2EE et je travaille actuellement sur le module EJB. Seulement je suis débutant et je n'arrive meme pas à executer Hellowrorld
******************************************************
classe greeting:
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
public class Greeting implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
@Id @GeneratedValue
private int id;
@Basic private String message;
@Basic private String language;
public Greeting() {}
public Greeting(String message, String language) {
this.message = message;
this.language = language;
}
public String toString() {
return "Greeting id=" + id + ", message=" + message + ", language=" + language;
}
}
*******************************************************
classe HelloWorld
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
public class HelloWorld {
private EntityManagerFactory emf;
private EntityManager em;
private String PERSISTENCE_UNIT_NAME = "hello-world";
public static void main(String[] args) {
HelloWorld hello = new HelloWorld();
hello.initEntityManager();
hello.create();
hello.read();
hello.closeEntityManager(); }
private void initEntityManager() {
emf = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
em = emf.createEntityManager();
}
private void closeEntityManager() {
em.close();
emf.close();
}
private void create() {
em.getTransaction().begin();
Greeting g_en = new Greeting("hello world", "en");
Greeting g_es = new Greeting("hola, mundo", "es");
Greeting[] greetings = new Greeting[]{g_en, g_es};
for(Greeting g : greetings) {
em.persist(g);
}
em.getTransaction().commit();
}
private void read() {
Greeting g = (Greeting) em.createQuery( "select g from Greeting g where g.language = :language").setParameter("language", "en").getSingleResult();
System.out.println("Query returned: " + g);
}
}
*********************************************
descripteur de deploiement:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="hello-world" transaction-type="RESOURCE_LOCAL">
<provider>oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider</provider>
<class>Greeting</class>
<properties>
<property name="toplink.jdbc.url" value="jdbc:sqlserver://172.16.48.199;databaseName=DEV_ALAIN_PAX_MUGISHA;integratedSecurity=true"/>
<property name="toplink.jdbc.user" value=""/>
<property name="toplink.jdbc.driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
<property name="toplink.jdbc.password" value=""/>
<property name="toplink.ddl-generation" value="drop-and-create-tables"/>
</properties>
</persistence-unit>
</persistence>
***********************************************
et a l'execution j'ai:
Exception in thread "main" java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/Persistence
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at HelloWorld.initEntityManager(HelloWorld.java:17)
at HelloWorld.main(HelloWorld.java:12)
************************************************************
quelqu'un pourrait m'eclaircir sur les configurations qui me manquent?
merci d'avance
Partager