Salut,
Dans un simple exemple d'EJB entité pour le mapping d'une table Departement, je tente de faire une insertion à la base mais ça ne marche pas, je n'ai pas d'erreurs.
Je plonge dans l'environnement suivant : Eclipse 3.4.2, JBOSS 4.2.1GA, EJB2.1 et XDoclet 1.2.2.
Heureusement les XDoclets me génère la structure suivante :
pack côté serveur :
DepartmentEntityEJB
DepartmentEntityEJBBean
DepartmentEntityEJBCMP
et pack côté client :
DepartmentEntityEJBData
DepartmentEntityEJBHome
DepartmentEntityEJBLocal
DepartmentEntityEJBLocalHome
DepartmentEntityEJBUtil
et bien sûr je rajoute l'interface : DepartmentEntityEJB
Je modifie la ma classe DepartmentEntityEJBBean de la façon suivante :
Je rajoute les champs de ma table departement : Integer id; String libelle;
et je modifie
public java.lang.Integer ejbCreate() throws javax.ejb.CreateException {
return null;
}
public void ejbPostCreate() throws javax.ejb.CreateException {
}
que je rends :
public java.lang.Integer ejbCreate(Integer id, String libelle) throws javax.ejb.CreateException {
setId(id);
setLibelle(libelle);
return null;
}
public void ejbPostCreate(Integer id, String libelle) throws javax.ejb.CreateException {
}
A l'aide de XDoclet heureusement, les autres interfaces et classes du côté du client seront mises à jour, et puis je passe au déploiement.
Je déploie, et je vois bien dans la console du serveur :
16:00:14,093 INFO [EjbModule] Deploying DepartmentEntityEJB
Au niveau du client, voila ce que je fait :
Je crée une nouvelle application JAVA
J'intègre le bloc client que m'a généré XDoclet.
Je rajoute les librairies runtime du serveur
Je code la fonction main de la façon suivante :
public static void main(String[] args) throws NamingException, RemoteException, CreateException, FinderException {
Properties prop = new Properties();
prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
prop.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
prop.put(Context.PROVIDER_URL, "jnp://localhost:1099");
DepartmentEntityEJBHome home = DepartmentEntityEJBUtil.getHome(prop);
home.create(1, "Département informatique");
System.out.println(home.findAll());
}
Quand j'exécute voici ce que ça donne :
log4j:WARN No appenders could be found for logger (org.jboss.remoting.transport.socket.MicroSocketClientInvoker).
log4j:WARN Please initialize the log4j system properly.
[DepartmentEntityEJB:1]
Par contre, au niveau de la base de données, absolument pas de modification.
Est-il normal ? auquel cas j'ai sauté une étape.
Est-il anormal ? où est ce que je me trompe ?
Voici à titre d'information mon fichier de configuration xml :
<entity id="ContainerManagedEntity_DepartmentEntityEJB">
<description><![CDATA[<!-- begin-xdoclet-definition -->]]></description>
<ejb-name>DepartmentEntityEJB</ejb-name>
<home>dao.DepartmentEntityEJBHome</home>
<remote>dao.DepartmentEntityEJB</remote>
<local-home>dao.DepartmentEntityEJBLocalHome</local-home>
<local>dao.DepartmentEntityEJBLocal</local>
<ejb-class>dao.DepartmentEntityEJBCMP</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.Integer</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>DepartmentEJBSCHEMA</abstract-schema-name>
<cmp-field id="CMPAttribute_1">
<description><![CDATA[<!-- begin-user-doc --> CMP Field id Returns the id]]></description>
<field-name>id</field-name>
</cmp-field>
<cmp-field id="CMPAttribute_2">
<description><![CDATA[<!-- begin-user-doc --> CMP Field libelle Returns the libelle]]></description>
<field-name>libelle</field-name>
</cmp-field>
<primkey-field>id</primkey-field>
<query>
<query-method>
<method-name>findAll</method-name>
<method-params>
</method-params>
</query-method>
<ejb-ql><![CDATA[SELECT OBJECT(a) FROM DepartmentEJBSCHEMA as a]]></ejb-ql>
</query>
<!-- Write a file named ejb-finders-DepartmentEntityEJBBean.xml if you want to define extra finders. -->
</entity>
Ah, une chose, je ne comprends pas
DepartmentEJBSCHEMA et à quel endroit le schéma DepartmentEJBSCHEMA est mappé à ma table qui s'appelle departement tout court ?
Pourquoi mes deux classes au niveau du serveur sont abstraites :
DepartmentEntityEJBBean
DepartmentEntityEJBCMP
? Comment le bean entité serait-il créé donc ?
Désolé d'avoir compliqué les choses.
Merci pour vos aides.

