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 :

Utiliser JPA/Hibernate avec JBoss et Oracle


Sujet :

Wildfly/JBoss Java

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    86
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 86
    Points : 42
    Points
    42
    Par défaut Utiliser JPA/Hibernate avec JBoss et Oracle
    Bonsoir,

    J'ai suivi le tutoriel de developpez.com (disponible ici) sur les EJB3 avec JBoss et Hibernate pour faire de la persistance.

    J'ai lancé l'exemple avec les EJB3, JBoss et Hibernate, le tout sans page web et cela fonctionne correctement.

    Mon problème c'est que tout ça est fait pour une ancienne version de JBoss et que je souhaiterais pouvoir faire passer tout cela sur JBoss 5.0.0.

    Voici mon code :

    entreprise.Entreprise.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
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    @Entity
    @Table(name="entreprise")
    @NamedQuery(name="ent.all",query="SELECT e FROM entreprise")
    public class Entreprise implements Serializable {
     
    	/**
             * 
             */
    	private static final long serialVersionUID = 2905066358946886642L;
    	@Column(name = "nom", nullable = false)
    	protected String nom;
    	@Column(name = "adresse", nullable = false)
    	protected String adresse;
    	@Column(name = "codepostal", nullable = false)
    	protected Integer codepostal;
    	@Column(name = "ville", nullable = false)
    	protected String ville;
    	@Column(name = "telephone", nullable = true)
    	protected Integer telephone;
    	@Column(name = "gerant", nullable = true)
    	protected String gerant;
    	@Column(name = "identifiant", nullable = false)
    	protected String identifiant;
    	@Column(name = "password", nullable = false)
    	protected String password;
     
    	/**
             * Default constructor. 
             */
    	public Entreprise() {
    		this.init("","",null,"",null,"","","");
    	}
     
    	public Entreprise(String nom, String adresse, Integer codepostal, String ville, Integer telephone, String gerant, String identifiant, String password) {
    		this.init( nom, adresse, codepostal, ville, telephone, gerant, identifiant, password);
    	}
     
    	private void init(String nom, String adresse, Integer codepostal, String ville, Integer telephone, String gerant, String identifiant, String password) {
    		this.nom = nom;
    		this.adresse = adresse;
    		this.codepostal = codepostal;
    		this.ville = ville;
    		this.telephone = telephone;
    		this.gerant = gerant;
    		this.identifiant = identifiant;
    		this.password = password;
    	}
     
    ... > Getters et Setters
    dao.Dao.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
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    @Stateless
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public class DAO implements IDao {
     
    	@PersistenceContext
    	private EntityManager em;
     
    	@Override
    	public void deleteOne(String nom) {
    		Entreprise ent = em.find(Entreprise.class, nom);
    		if (ent == null) {
    			throw new DaoException(2);
    		}
    		em.remove(ent);
    	}
     
    	@Override
    	public void deleteOne(Entreprise ent) {
    		if (ent == null) {
    			throw new DaoException(2);
    		}
    		em.remove(ent);
    		ent = null;
    	}
     
    	@SuppressWarnings("unchecked")
    	@Override
    	public List<Entreprise> getAll() {
    		return em.createQuery("select e from Entreprise e").getResultList();
    	}
     
    	@Override
    	public Entreprise getOne(String nom) {
    		return em.find(Entreprise.class, nom);
    	}
     
    	@Override
    	public Entreprise saveOne(Entreprise entreprise) {
    		em.persist(entreprise);
    		return entreprise;
    	}
     
    	@Override
    	public Entreprise updateOne(Entreprise entreprise) {
    		return em.merge(entreprise);
    	}
     
    }
    META-INF/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
    <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="jpa">
     
            <!-- le fournisseur JPA est Hibernate -->
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
     
            <!-- la DataSource JTA gérée par l'environnement Java EE5 -->
            <jta-data-source>java:/datasource</jta-data-source>
     
            <properties>
                <!-- recherche des entités de la couche JBA -->
                <property name="hibernate.archive.autodetection" value="class, hbm" />
     
                <!-- logs SQL Hibernate
                    <property name="hibernate.show_sql" value="true"/>
                    <property name="hibernate.format_sql" value="true"/>
                    <property name="use_sql_comments" value="true"/>
                -->
     
                <!-- le type de SGBD géré -->
                <property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect" />
     
                <!-- recréation de toutes les tables (drop+create) au déploiement de l'unité de persistence -->
                <property name="hibernate.hbm2ddl.auto" value="create" />
     
            </properties>
        </persistence-unit>
     
    </persistence>
    Jusque là tout correspond globalement au tutoriel, là où cela devient compliqué pour moi, c'est qu'il y a un fichier
    jboss-config.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
    <?xml version="1.0" encoding="UTF-8"?>
     
    <deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_1_0.xsd"
    	xmlns="urn:jboss:bean-deployer:2.0">
     
    	<!-- factory de la DataSource -->
    	<bean name="datasourceFactory" class="org.jboss.resource.adapter.jdbc.local.LocalTxDataSource">
    		<!-- nom JNDI de la DataSource -->
    		<property name="jndiName">java:/datasource</property>
     
    		<!-- base de données gérée -->
    		<property name="driverClass">oracle.jdbc.OracleDriver</property>
    		<property name="connectionURL">jdbc:oracle:thin:@localhost:1521:mabase</property>
    		<property name="userName">login</property>
    		<property name="password">password</property>
     
    		<!-- propriétés pool de connexions -->
    		<property name="minSize">0</property>
    		<property name="maxSize">10</property>
    		<property name="blockingTimeout">1000</property>
    		<property name="idleTimeout">100000</property>
     
    		<!-- gestionnaire de transactions, ici JTA -->
    		<property name="transactionManager">
    			<inject bean="TransactionManager" />
    		</property>
    		<!-- gestionnaire du cache Hibernate -->
    		<property name="cachedConnectionManager">
    			<inject bean="CachedConnectionManager" />
    		</property>
    		<!-- propriétés instanciation JNDI ? -->
    		<property name="initialContextProperties">
    			<inject bean="InitialContextProperties" />
    		</property>
    	</bean>
     
    	<!-- la DataSource est demandée à une factory -->
    	<bean name="datasource" class="java.lang.Object">
    		<constructor factoryMethod="getDatasource">
    			<factory bean="datasourceFactory" />
    		</constructor>
    	</bean>
     
    </deployment>
    un fichier embedded-jboss-beans.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
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    <?xml version="1.0" encoding="UTF-8"?>
     
    <deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_1_0.xsd"
                xmlns="urn:jboss:bean-deployer:2.0">
       <bean name="Naming" class="org.jnp.server.SingletonNamingServer"/>
     
       <bean name="InitialContextProperties" class="java.util.Hashtable">
          <constructor>
          <parameter class="java.util.Map">
                <map keyClass="java.lang.String" valueClass="java.lang.String">
                   <entry>
                      <key>java.naming.factory.initial</key>
                      <value>org.jnp.interfaces.LocalOnlyContextFactory</value>
                   </entry>
                   <entry>
                       <key>java.naming.factory.url.pkgs</key>
                       <value>org.jboss.naming:org.jnp.interfaces</value>
                   </entry>
                </map>
          </parameter>
          </constructor>
       </bean>
     
       <bean name="java:comp/Initializer" class="org.jboss.ejb3.embedded.JavaCompInitializer">
          <property name="jndiProperties"><inject bean="InitialContextProperties"/></property>
       </bean>
     
       <bean name="XidFactory" class="org.jboss.tm.XidFactoryImpl"/>
     
       <bean name="XidFactoryMBean" class="org.jboss.ejb3.embedded.XidFactoryMBean">
          <constructor>
             <parameter class="org.jboss.tm.XidFactoryBase">
                <inject bean="XidFactory"/>
             </parameter>
          </constructor>
       </bean>
     
       <bean name="TransactionManagerInitializer" class="org.jboss.tm.TransactionManagerInitializer">
          <property name="xidFactory"><inject bean="XidFactory"/></property>
          <property name="initialContextProperties"><inject bean="InitialContextProperties"/></property>
       </bean>
     
       <bean name="UserTransaction" class="org.jboss.ejb3.embedded.UserTransactionImpl">
          <demand>TransactionManagerInitializer</demand>
       </bean>
     
       <bean name="UserTransactionBinding" class="org.jboss.ejb3.embedded.JndiBinder">
          <property name="jndiProperties"><inject bean="InitialContextProperties"/></property>
          <property name="target"><inject bean="UserTransaction"/></property>
          <property name="bindTo">UserTransaction</property>
          <property name="serializable">false</property>
       </bean>
     
     
       <bean name="TransactionManager" class="java.lang.Object">
          <constructor factoryMethod="getTransactionManager">
             <factory bean="TransactionManagerInitializer"/>
          </constructor>
       </bean>
       <bean name="CachedConnectionManager" class="org.jboss.resource.connectionmanager.CachedConnectionManagerReference">
          <property name="transactionManager"><inject bean="TransactionManager"/></property>
       </bean>
     
       <!--
          <bean class="org.jboss.jdbc.HypersonicDatabase"
            name="jboss:service=Hypersonic,database=localDB">
            <property name="database">localDB</property>
            <property name="inProcessMode">true</property>
            <property name="dbDataDir">.</property>
          </bean>
       -->
     
        <!-- Not needed without JMS
     
       <bean name="DefaultDSBootstrap" class="org.jboss.resource.adapter.jdbc.local.LocalTxDataSource">
          <property name="driverClass">org.hsqldb.jdbcDriver</property>
          <property name="connectionURL">jdbc:hsqldb:.</property>
          <property name="userName">sa</property>
          <property name="jndiName">java:/DefaultDS</property>
          <property name="minSize">0</property>
          <property name="maxSize">10</property>
          <property name="blockingTimeout">1000</property>
          <property name="idleTimeout">100000</property>
          <property name="transactionManager"><inject bean="TransactionManager"/></property>
          <property name="cachedConnectionManager"><inject bean="CachedConnectionManager"/></property>
          <property name="initialContextProperties"><inject bean="InitialContextProperties"/></property>
       </bean>
     
       <bean name="DefaultDS" class="java.lang.Object">
          <constructor factoryMethod="getDatasource">
             <factory bean="DefaultDSBootstrap"/>
          </constructor>
       </bean>
        -->
     
       <!--
       <bean name="TimerServiceFactory" class="org.jboss.ejb3.timerservice.quartz.QuartzTimerServiceFactory">
          <property name="properties">
            	org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreCMT
                org.quartz.jobStore.nonManagedTXDataSource=myDS
                org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.HSQLDBDelegate
                org.quartz.jobStore.tablePrefix=QRTZ_
                org.quartz.jobStore.dataSource=myDS
     
    	        # To get it to work with hypersonic
    	        # FIXME: this doesn't lock the row
                org.quartz.jobStore.selectWithLockSQL=SELECT * FROM qrtz_locks WHERE lock_name = ?
     
            	# from quartz.properties
                org.quartz.scheduler.instanceName=JBossEJB3QuartzScheduler
                org.quartz.scheduler.rmi.export=false
                org.quartz.scheduler.rmi.proxy=false
                org.quartz.scheduler.wrapJobExecutionInUserTransaction=false
     
                org.quartz.threadPool.class=org.quartz.simpl.SimpleThreadPool
                org.quartz.threadPool.threadCount=10
                org.quartz.threadPool.threadPriority=5
                org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread=true
     
            	org.quartz.jobStore.misfireThreshold=60000
          </property>
          <property name="dataSource">java:/DefaultDS</property>
          <property name="sqlProperties">
             CREATE_DB_ON_STARTUP = TRUE
     
             CREATE_TABLE_JOB_DETAILS = CREATE TABLE qrtz_job_details(JOB_NAME VARCHAR(80) NOT NULL, JOB_GROUP VARCHAR(80) NOT NULL, \
                DESCRIPTION VARCHAR(120) NULL, JOB_CLASS_NAME VARCHAR(128) NOT NULL, IS_DURABLE VARCHAR(1) NOT NULL, \
                IS_VOLATILE VARCHAR(1) NOT NULL, IS_STATEFUL VARCHAR(1) NOT NULL, REQUESTS_RECOVERY VARCHAR(1) NOT NULL, \
                JOB_DATA BINARY NULL, PRIMARY KEY (JOB_NAME,JOB_GROUP))
             CREATE_TABLE_JOB_LISTENERS = CREATE TABLE qrtz_job_listeners(JOB_NAME VARCHAR(80) NOT NULL, JOB_GROUP VARCHAR(80) NOT NULL, \
                JOB_LISTENER VARCHAR(80) NOT NULL, PRIMARY KEY (JOB_NAME,JOB_GROUP,JOB_LISTENER), FOREIGN KEY (JOB_NAME,JOB_GROUP) \
                REFERENCES QRTZ_JOB_DETAILS(JOB_NAME,JOB_GROUP))
             CREATE_TABLE_TRIGGERS = CREATE TABLE qrtz_triggers(TRIGGER_NAME VARCHAR(80) NOT NULL, TRIGGER_GROUP VARCHAR(80) NOT NULL, \
                JOB_NAME VARCHAR(80) NOT NULL, JOB_GROUP VARCHAR(80) NOT NULL, IS_VOLATILE VARCHAR(1) NOT NULL, DESCRIPTION VARCHAR(120) NULL, \
                NEXT_FIRE_TIME NUMERIC(13) NULL, PREV_FIRE_TIME NUMERIC(13) NULL, TRIGGER_STATE VARCHAR(16) NOT NULL, \
                TRIGGER_TYPE VARCHAR(8) NOT NULL, START_TIME NUMERIC(13) NOT NULL, END_TIME NUMERIC(13) NULL, CALENDAR_NAME VARCHAR(80) NULL, \
                MISFIRE_INSTR NUMERIC(2) NULL, JOB_DATA BINARY NULL, PRIMARY KEY (TRIGGER_NAME,TRIGGER_GROUP), FOREIGN KEY (JOB_NAME,JOB_GROUP) \
                REFERENCES QRTZ_JOB_DETAILS(JOB_NAME,JOB_GROUP))
             CREATE_TABLE_SIMPLE_TRIGGERS = CREATE TABLE qrtz_simple_triggers(TRIGGER_NAME VARCHAR(80) NOT NULL, \
                TRIGGER_GROUP VARCHAR(80) NOT NULL, REPEAT_COUNT NUMERIC(7) NOT NULL, REPEAT_INTERVAL NUMERIC(12) NOT NULL, \
                TIMES_TRIGGERED NUMERIC(7) NOT NULL, PRIMARY KEY (TRIGGER_NAME,TRIGGER_GROUP), FOREIGN KEY (TRIGGER_NAME,TRIGGER_GROUP) \
                REFERENCES QRTZ_TRIGGERS(TRIGGER_NAME,TRIGGER_GROUP))
             CREATE_TABLE_CRON_TRIGGERS = CREATE TABLE qrtz_cron_triggers(TRIGGER_NAME VARCHAR(80) NOT NULL, \
                TRIGGER_GROUP VARCHAR(80) NOT NULL, CRON_EXPRESSION VARCHAR(80) NOT NULL, TIME_ZONE_ID VARCHAR(80), \
                PRIMARY KEY (TRIGGER_NAME,TRIGGER_GROUP), FOREIGN KEY (TRIGGER_NAME,TRIGGER_GROUP) \
                REFERENCES QRTZ_TRIGGERS(TRIGGER_NAME,TRIGGER_GROUP))
             CREATE_TABLE_BLOB_TRIGGERS = CREATE TABLE qrtz_blob_triggers(TRIGGER_NAME VARCHAR(80) NOT NULL, \
                TRIGGER_GROUP VARCHAR(80) NOT NULL, BLOB_DATA BINARY NULL, PRIMARY KEY (TRIGGER_NAME,TRIGGER_GROUP), \
                FOREIGN KEY (TRIGGER_NAME,TRIGGER_GROUP) REFERENCES QRTZ_TRIGGERS(TRIGGER_NAME,TRIGGER_GROUP))
             CREATE_TABLE_TRIGGER_LISTENERS = CREATE TABLE qrtz_trigger_listeners(TRIGGER_NAME VARCHAR(80) NOT NULL, \
                TRIGGER_GROUP VARCHAR(80) NOT NULL, TRIGGER_LISTENER VARCHAR(80) NOT NULL, \
                PRIMARY KEY (TRIGGER_NAME,TRIGGER_GROUP,TRIGGER_LISTENER), FOREIGN KEY (TRIGGER_NAME,TRIGGER_GROUP) \
                REFERENCES QRTZ_TRIGGERS(TRIGGER_NAME,TRIGGER_GROUP))
             CREATE_TABLE_CALENDARS = CREATE TABLE qrtz_calendars(CALENDAR_NAME VARCHAR(80) NOT NULL, CALENDAR BINARY NOT NULL, \
                PRIMARY KEY (CALENDAR_NAME))
             CREATE_TABLE_PAUSED_TRIGGER_GRPS = CREATE TABLE qrtz_paused_trigger_grps(TRIGGER_GROUP VARCHAR(80) NOT NULL, \
                PRIMARY KEY (TRIGGER_GROUP))
             CREATE_TABLE_FIRED_TRIGGERS = CREATE TABLE qrtz_fired_triggers(ENTRY_ID VARCHAR(95) NOT NULL, TRIGGER_NAME VARCHAR(80) NOT NULL, \
                TRIGGER_GROUP VARCHAR(80) NOT NULL, IS_VOLATILE VARCHAR(1) NOT NULL, INSTANCE_NAME VARCHAR(80) NOT NULL, \
                FIRED_TIME NUMERIC(13) NOT NULL, STATE VARCHAR(16) NOT NULL, JOB_NAME VARCHAR(80) NULL, JOB_GROUP VARCHAR(80) NULL, \
                IS_STATEFUL VARCHAR(1) NULL, REQUESTS_RECOVERY VARCHAR(1) NULL, PRIMARY KEY (ENTRY_ID))
             CREATE_TABLE_SCHEDULER_STATE = CREATE TABLE qrtz_scheduler_state(INSTANCE_NAME VARCHAR(80) NOT NULL, \
                LAST_CHECKIN_TIME NUMERIC(13) NOT NULL, CHECKIN_INTERVAL NUMERIC(13) NOT NULL, RECOVERER VARCHAR(80) NULL, \
                PRIMARY KEY (INSTANCE_NAME))
             CREATE_TABLE_LOCKS = CREATE TABLE qrtz_locks(LOCK_NAME VARCHAR(40) NOT NULL, PRIMARY KEY (LOCK_NAME))
             INSERT_TRIGGER_ACCESS = INSERT INTO qrtz_locks values('TRIGGER_ACCESS')
             INSERT_JOB_ACCESS = INSERT INTO qrtz_locks values('JOB_ACCESS')
             INSERT_CALENDAR_ACCESS = INSERT INTO qrtz_locks values('CALENDAR_ACCESS')
             INSERT_STATE_ACCESS = INSERT INTO qrtz_locks values('STATE_ACCESS')
             INSERT_MISFIRE_ACCESS = INSERT INTO qrtz_locks values('MISFIRE_ACCESS')
          </property>
       </bean>
     
       -->
     
    </deployment>
    un fichier jndi.properties.

    Enfin, pour lancer l'application ils utilisent ceci dans un main :
    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
    	public static void main(String[] args) throws ParseException, NamingException {
    		// on démarre le conteneur EJB3 JBoss
    		// les fichiers de configuration ejb3-interceptors-aop.xml et
    		// embedded-jboss-beans.xml sont exploités
    		EJB3StandaloneBootstrap.boot(null);
     
    		// Création des beans propres à l'application
    		EJB3StandaloneBootstrap.deployXmlResource("META-INF/jboss-config.xml");
     
    		// Deploy all EJBs found on classpath (slow, scans all)
    		// EJB3StandaloneBootstrap.scanClasspath();
     
    		// on déploie tous les EJB trouvés dans le classpath de l'application
    		EJB3StandaloneBootstrap.scanClasspath("bin".replace("/", File.separator));
     
    		// On initialise le contexte JNDI. Le fichier jndi.properties est exploité
    		InitialContext initialContext = new InitialContext();
     
    		// instanciation couche service
    		service = (IService) initialContext.lookup("Service/local");
    		// on vide la base
    		clean();
    		// on la remplit
    		fill();
    		// on vérifie visuellement
    		dumpPersonnes();
    		// on arrête le conteneur Ejb
    		EJB3StandaloneBootstrap.shutdown();
    	}
    Alors que moi je souhaiterais dans un premier juste dans une page JSP afficher toutes les entreprises enregistrés.

    J'espère que vous pourrez m'aider à comprendre comment faire pour passer de l'ancienne version de JBoss à la nouvelle.

    Merci d'avance.

  2. #2
    Membre éprouvé
    Avatar de hasalex
    Homme Profil pro
    Développeur Java
    Inscrit en
    Janvier 2009
    Messages
    879
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Janvier 2009
    Messages : 879
    Points : 1 269
    Points
    1 269
    Par défaut
    Et quel est ton problème avec JBoss 5 ?

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    86
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 86
    Points : 42
    Points
    42
    Par défaut
    Mon problème c'est que je ne sais pas à quoi correspondent les 3 derniers fichiers, et où faut il mettre leur contenu étant donné qu'ils n'existent plus dans les nouvelles spécifications.

  4. #4
    Membre éprouvé
    Avatar de hasalex
    Homme Profil pro
    Développeur Java
    Inscrit en
    Janvier 2009
    Messages
    879
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Janvier 2009
    Messages : 879
    Points : 1 269
    Points
    1 269
    Par défaut
    Ton exemple initial n'utilise pas vraiment JBoss, mais juste le composant EJB3 qui permet d'ajouter le support des EJB3 à une application autonome.

    Dans JBoss 5, les EJB3 sont directement supportés, tu n'as donc pas besoin de tout cela. Tu dois conserver tes classes, ton fichiers persistence.xml et empaqueter tout cela dans un fichier jar.
    Ensuite, tu dois déployer une datasource, pour laquelle tu peux t'inspirer des fichiers dans docs/examples/jca.

    Pour ta JSP, tu peux reprendre le bout de code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    		// On initialise le contexte JNDI. Le fichier jndi.properties est exploité
    		InitialContext initialContext = new InitialContext();
     
    		// instanciation couche service
    		service = (IService) initialContext.lookup("Service/local");
    Et compléter avec ce que tu veux en faire...

  5. #5
    Membre du Club
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    86
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 86
    Points : 42
    Points
    42
    Par défaut
    Merci, je venais justement de me rendre compte qu'il fallait un fichier oracle-ds.xml.

    J'ai rempli ce fichier, mais j'ai une erreur J'ai essayé de bindé Service en l'ajoutant <attribute name="DefaultQueueJNDIContext">/Service</attribute> dans messaging-service.xml mais du coup j'ai eut local not bound que j'ai bindé dans destinations-service.xml => erreur de cast entre IService et Queue.

    Comment faire pour avoir ce Service/local ?

    Merci

  6. #6
    Membre du Club
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    86
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 86
    Points : 42
    Points
    42
    Par défaut
    J'ai réussi à résoudre ce problème, j'ai mis :

    ServiceLocal service = (ServiceLocal) initialContext.lookup("Application/Service/local-service.ServiceLocal");

    Pour explication, je déploie le tout dans un ear (Application) qui contient mes EJB et mon WAR.

    Et maintenant nouvelle erreur, Entreprise n'est pas mappé alors qu'il y a bien le fichier persistence.xml dans META-INF de l'EJB Entreprise.

    Je vais d'erreur en erreur ! ><'

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Utiliser Session Bean avec JBoss 7.1
    Par hpnet dans le forum Wildfly/JBoss
    Réponses: 4
    Dernier message: 06/08/2012, 08h48
  2. Réponses: 2
    Dernier message: 11/06/2009, 00h44
  3. Problème d'utilisation JPA+Hibernate+Spring + DB2
    Par menzlitsh dans le forum JPA
    Réponses: 9
    Dernier message: 27/02/2009, 11h19
  4. Utilisation des MBeans avec JBoss
    Par viggen dans le forum Wildfly/JBoss
    Réponses: 1
    Dernier message: 22/03/2007, 17h32

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