IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Wildfly/JBoss Java Discussion :

Développement d'un ejb3.0 sous Eclipse avec JBoss et Oracle 10g express


Sujet :

Wildfly/JBoss Java

  1. #1
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Juin 2009
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Juin 2009
    Messages : 3
    Points : 1
    Points
    1
    Par défaut Développement d'un ejb3.0 sous Eclipse avec JBoss et Oracle 10g express
    Bonjour,

    Je me heurte à une exception due, je pense, à la connexion entre jBoss(mon serveur d'application) et Oracle 10g express.

    Tout d'abord, voici le context :

    J'ai créer mes tables Etudiant, Cours et EtudiantCours avec sqlplus. Ensuite, 2 triggers et 2 séquences pour gérer les clés primaires des tables Etudiants et Cours.

    Ensuite sous Eclipse, j'ai crée un projet JPA -> Générer les entity et voici ce que j'ai obtenu :

    Entity Etudiant :

    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
    package entity;
     
    import java.io.Serializable;
    import java.util.Set;
    import javax.persistence.Entity;
    import javax.persistence.Id;
    import javax.persistence.ManyToMany;
     
    @Entity
    public class Etudiant implements Serializable {
    	@Id
    	private long nume;
    	private String nome;
    	private String prenome;
     
    	@ManyToMany(mappedBy="etudiantCollection")
    	private Set<Cours> coursCollection;
     
    	private static final long serialVersionUID = 1L;
     
    	public Etudiant() {
    		super();
    	}
     
    	public Etudiant(String nom, String prenom) {
    		this.nume = 1;
    		this.nome = nom;
    		this.prenome = prenom;
    	}
     
    	public long getNume() {
    		return this.nume;
    	}
     
    	public void setNume(long nume) {
    		this.nume = nume;
    	}
     
    	public String getNome() {
    		return this.nome;
    	}
     
    	public void setNome(String nome) {
    		this.nome = nome;
    	}
     
    	public String getPrenome() {
    		return this.prenome;
    	}
     
    	public void setPrenome(String prenome) {
    		this.prenome = prenome;
    	}
     
    	public Set<Cours> getCoursCollection() {
    		return this.coursCollection;
    	}
     
    	public void setCoursCollection(Set<Cours> coursCollection) {
    		this.coursCollection = coursCollection;
    	}
     
    }
    Entity Cours

    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
    package entity;
     
    import java.io.Serializable;
    import java.util.Set;
    import javax.persistence.Entity;
    import javax.persistence.Id;
    import javax.persistence.JoinColumn;
    import javax.persistence.JoinTable;
    import javax.persistence.ManyToMany;
     
    @Entity
    public class Cours implements Serializable {
    	@Id
    	private long idc;
    	private String matiere;
     
    	@ManyToMany
    	@JoinTable(name="ETUDIANTCOURS",
    		joinColumns=@JoinColumn(name="IDC"),
    		inverseJoinColumns=@JoinColumn(name="NUME"))
    	private Set<Etudiant> etudiantCollection;
     
    	private static final long serialVersionUID = 1L;
     
    	public Cours() {
    		super();
    	}
     
    	public long getIdc() {
    		return this.idc;
    	}
     
    	public void setIdc(long idc) {
    		this.idc = idc;
    	}
     
    	public String getMatiere() {
    		return this.matiere;
    	}
     
    	public void setMatiere(String matiere) {
    		this.matiere = matiere;
    	}
     
    	public Set<Etudiant> getEtudiantCollection() {
    		return this.etudiantCollection;
    	}
     
    	public void setEtudiantCollection(Set<Etudiant> etudiantCollection) {
    		this.etudiantCollection = etudiantCollection;
    	}
     
    }
    Voila pour mes entity.

    Ensuite, j'ai créé sous Eclipse un projet EJB avec une interface GestionEtudiant et un session bean GestionEtudiantBean

    Voici le code :


    Interface GestionEtudiant.java

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    package session;
     
    import java.util.List;
    import javax.ejb.Remote;
    import entity.Etudiant;
     
    @Remote
    public interface GestionEtudiant {
    	public void ajouter(Etudiant etudiant);
    	public Etudiant rechercherEtudiant(String nom);
    	public List<Etudiant> listerTousLesEtudiants();
    }
    Session bean GestionEtudiantBean.java

    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
    package session;
     
    import java.util.List;
     
    import javax.ejb.Stateless;
    import javax.persistence.EntityManager;
    import javax.persistence.PersistenceContext;
     
    import entity.Etudiant;
     
    @Stateless
    public class GestionEtudiantBean implements GestionEtudiant{
     
    	@PersistenceContext
    	EntityManager em;
     
    	public void ajouter(Etudiant etudiant) {
    		em.persist(etudiant);
    	}
     
    	public Etudiant rechercherEtudiant(String nomE) {
    		return em.find(Etudiant.class, nomE);
    	}
     
    	public List<Etudiant> listerTousLesEtudiants() {
    		return em.createQuery("SELECT e FROM Etudiant e").getResultList();
    	}
    }

    Pour faire plus simple, j'ai pris mes 2 entity beans et les ai mis dans mon projet EJB dans un package entity et mon session bean et moninterface dans un package session.

    Ensuite, la création d'un client pour tester, simple projet java :

    GestionDEtudiant.java

    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
    package client;
     
    import java.util.Iterator;
    import java.util.List;
     
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import session.GestionEtudiant;
    import entity.Etudiant;
     
    public class GestionDEtudiant {
    	public static void main(String[] args) {
    		try {
    	        Context context = new InitialContext();
    	        GestionEtudiant gEtu = (GestionEtudiant) context.lookup("GestionEtudiantBean/remote");
     
    	        gEtu.ajouter(new Etudiant("XXX","YYY"));
    	        gEtu.ajouter(new Etudiant("XXX","YYY"));
    	        gEtu.ajouter(new Etudiant("XXX","YYY"));
    	        gEtu.ajouter(new Etudiant("XXX","YYY"));
    	        gEtu.ajouter(new Etudiant("XXX","YYY"));
     
    	        /*List<Etudiant> etudiant = gEtu.listerTousLesEtudiants();
    	        for (Iterator iter = etudiant.iterator(); iter.hasNext();) {
    	           Etudiant eachEtudiant = (Etudiant) iter.next();
    	           System.out.println(eachEtudiant.getNume()+" : "+eachEtudiant.getNome()+" "+eachEtudiant.getPrenome());
    	        }*/
    	     } catch (Exception e) {
    	    	 e.printStackTrace();
    	     }
    	}
    }
    Ensuite, j'ai créé un répertoire META-INF avec le fichier persistence.xml

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    sistence>
    	<persistence-unit name="TestEJB">
    		<jta-data-source>java:/DefaultDS</jta-data-source>
    		<properties>
    			<property name="hibernate.hbm2ddl.auto" value="update"/>
    		</properties>
    	</persistence-unit>
    </persistence>
    A la racine du projet, j'ai un fichier jndi.properties

    java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
    java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
    java.naming.provider.url=localhost:1099
    J'ai testé mon application avec le driver fournit par jBoss hsqldb et ca marche nickel, mes insertions sont bien effectuées

    J'ai ensuite configuré jBoss pour qu'il communique avec Oracle

    Et la après la premère isertion, une exception est levée, voici la stacktrace :
    (Si je vide la table ou je fais les insertions et que je réexécute mon client, la première insertion se refait et une exception est levé à la deuxième exception, si je laisse la table comme elle est, une exception est levé à chaque tentative)

    java.lang.reflect.UndeclaredThrowableException
    at $Proxy0.ajouter(Unknown Source)
    at client.GestionDEtudiant.main(GestionDEtudiant.java:19)
    Caused by: java.rmi.MarshalException: Failed to communicate. Problem during marshalling/unmarshalling; nested exception is:
    java.io.StreamCorruptedException: invalid type code: FF
    at org.jboss.remoting.transport.socket.SocketClientInvoker.transport(SocketClientInvoker.java:306)
    at org.jboss.remoting.RemoteClientInvoker.invoke(RemoteClientInvoker.java:143)
    at org.jboss.remoting.Client.invoke(Client.java:525)
    at org.jboss.remoting.Client.invoke(Client.java:488)
    at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:55)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:61)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    at org.jboss.aspects.security.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:53)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:77)
    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:102)
    ... 2 more
    Caused by: java.io.StreamCorruptedException: invalid type code: FF
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.readArray(Unknown Source)
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
    at java.io.ObjectInputStream.readSerialData(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
    at java.io.ObjectInputStream.readSerialData(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
    at java.io.ObjectInputStream.readSerialData(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
    at java.io.ObjectInputStream.readSerialData(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
    at java.io.ObjectInputStream.readSerialData(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
    at java.io.ObjectInputStream.readSerialData(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.readObject(Unknown Source)
    at org.jboss.remoting.serialization.impl.java.JavaSerializationManager.receiveObject(JavaSerializationManager.java:128)
    at org.jboss.remoting.marshal.serializable.SerializableUnMarshaller.read(SerializableUnMarshaller.java:66)
    at org.jboss.remoting.transport.socket.SocketClientInvoker.transport(SocketClientInvoker.java:279)
    ... 14 more
    La JRE configué pour jBoss est la jre6, pour les projets c'est par défault, donc la 6 aussi

    Donc je n'arrive pas à comprendre cette erreur, pouvez vous m'éclairer, j'ai vu sur le net, qu'il pouvait y avoir des incompatibilités entre les jre

    Merci de votre aide

  2. #2
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Juin 2009
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Juin 2009
    Messages : 3
    Points : 1
    Points
    1
    Par défaut
    Voici ce que j'ai pu retirer de l'exception qui était levée (avec e.getClass()) :

    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
    00:23:09,613 WARN  [JDBCExceptionReporter] SQL Error: 1, SQLState: 23000
    00:23:09,613 ERROR [JDBCExceptionReporter] ORA-00001: violation de contrainte unique (LC627992.PK_ETUDIANT)
     
    00:23:09,613 WARN  [JDBCExceptionReporter] SQL Error: 1, SQLState: 23000
    00:23:09,613 ERROR [JDBCExceptionReporter] ORA-00001: violation de contrainte unique (LC627992.PK_ETUDIANT)
     
    00:23:09,613 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
    org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
    	at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
    	at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    	at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:249)
    	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
    	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
    	at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
    	at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
    	at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
    	at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
    	at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:515)
    	at org.jboss.tm.TransactionImpl.doBeforeCompletion(TransactionImpl.java:1491)
    	at org.jboss.tm.TransactionImpl.beforePrepare(TransactionImpl.java:1110)
    	at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:324)
    	at org.jboss.tm.TxManager.commit(TxManager.java:240)
    	at org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:175)
    	at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:87)
    	at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
    	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
    	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
    	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
    	at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:102)
    	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
    	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
    	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:263)
    	at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:106)
    	at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
    	at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:828)
    	at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:681)
    	at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:358)
    	at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:412)
    	at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:239)
    Caused by: java.sql.BatchUpdateException: ORA-00001: violation de contrainte unique (LC627992.PK_ETUDIANT)
     
    	at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:343)
    	at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10656)
    	at org.jboss.resource.adapter.jdbc.WrappedStatement.executeBatch(WrappedStatement.java:519)
    	at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
    	at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
    	... 34 more
    A priori, si on regarde les premières lignes, on voit qu'il y a une erreur de clé primaire, j'ai donc pensé à mes triggers que se déclenchait mal ou pas du tout.

    J'ai donc revérifié mes triggers, et je les ai testé en ligne de commande avec une insertion et ca marche nickel

    Donc je ne vois toujours pas pourquoi il me lève cette exception...

  3. #3
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Juin 2009
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : Canada

    Informations forums :
    Inscription : Juin 2009
    Messages : 3
    Points : 1
    Points
    1
    Par défaut
    J'ai encore effectuer une modification qui fait que ca marche :

    Dans mon entity bean Etudiant.java, j'ai modifié le constructeur :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    public Etudiant(int i,String nom, String prenom) {
    		setNume(i);
    		setNome(nom);
    		setPrenome(prenom);
    	}
    Dans mon client, j'ai modifié les insertions :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    gEtu.ajouter(new Etudiant(2,"XXX","YYY"));
    	        gEtu.ajouter(new Etudiant(3,"XXX","YYY"));
    	        gEtu.ajouter(new Etudiant(4,"XXX","YYY"));
    	        gEtu.ajouter(new Etudiant(5,"XXX","YYY"));
    	        gEtu.ajouter(new Etudiant(6,"XXX","YYY"));
    Le premier arguement du constructeur est la clé primaire, étant donné que j'avai des insertions effectué dans ma table, j'ai pris soin de mettre des valeurs nouvelles.

    Et la, les insertions marche nickel

    Donc à ce que je vois, c'est qu'avec l'utilisation des ejbs, les triggers ne se déclenchent pas, pourquoi ? ou est-ce qu'il y a une autre explication ?

Discussions similaires

  1. Réponses: 1
    Dernier message: 21/12/2011, 10h18
  2. Développer une application web sous Eclipse avec applet JSP
    Par bard123 dans le forum Eclipse Java
    Réponses: 4
    Dernier message: 05/04/2008, 22h40
  3. Erreur sous eclipse avec Scanner
    Par bugland dans le forum Eclipse Java
    Réponses: 3
    Dernier message: 11/01/2007, 15h28
  4. [Tomcat]application Web sous eclipse avec Tomcat 5.5.12
    Par toda dans le forum Eclipse Java
    Réponses: 3
    Dernier message: 20/12/2005, 03h07
  5. [Plugin]Lancement d'un projet JSP sous Eclipse avec Tomcat
    Par samios dans le forum Eclipse Java
    Réponses: 2
    Dernier message: 25/08/2004, 18h03

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo