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

JPA Java Discussion :

Je ne comprends pas le persistence.xml


Sujet :

JPA Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Expert confirmé
    Avatar de sekaijin
    Homme Profil pro
    Urbaniste
    Inscrit en
    Juillet 2004
    Messages
    4 205
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Urbaniste
    Secteur : Santé

    Informations forums :
    Inscription : Juillet 2004
    Messages : 4 205
    Par défaut Je ne comprends pas le persistence.xml
    Bonjour,
    J'ai un fichier persistance.xml contenant deux unités
    Code xml : 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
    <?xml version="1.0" encoding="UTF-8"?>
    <!--
     Licensed to the Apache Software Foundation (ASF) under one
     or more contributor license agreements.  See the NOTICE file
     distributed with this work for additional information
     regarding copyright ownership.  The ASF licenses this file
     to you under the Apache License, Version 2.0 (the
     "License"); you may not use this file except in compliance
     with the License.  You may obtain a copy of the License at
     
     http://www.apache.org/licenses/LICENSE-2.0
     
     Unless required by applicable law or agreed to in writing,
     software distributed under the License is distributed on an
     "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     KIND, either express or implied.  See the License for the
     specific language governing permissions and limitations
     under the License.   
    -->
    <persistence xmlns="http://java.sun.com/xml/ns/persistence"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        version="1.0">
     
        <persistence-unit name="unit1" transaction-type="RESOURCE_LOCAL">
            <!--jta-data-source></jta-data-source-->
            <non-jta-data-source>osgi:services/javax.sql.DataSource/(name=source1)</non-jta-data-source>
            <class>foo.echange.model.I48500EventStore</class>
            <exclude-unlisted-classes>true</exclude-unlisted-classes>
     
            <properties>
                <!-- These properties are creating the database on the fly. We are using them to avoid users having
                to create a database to run the sample. This is not something that should be used in production.
                See also the create=true line in the ariestrader-derby-ds blueprint meta data -->
                <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
                <property name="openjpa.jdbc.DBDictionary" value="oracle"/>
            </properties>
        </persistence-unit>
     
     
        <persistence-unit name="unit2" transaction-type="RESOURCE_LOCAL">
            <!--jta-data-source></jta-data-source-->
            <non-jta-data-source>osgi:services/javax.sql.DataSource/(name=source2)</non-jta-data-source>
            <class>foo.echange.model.I48502EventStore</class>
            <exclude-unlisted-classes>true</exclude-unlisted-classes>
     
            <properties>
                <!-- These properties are creating the database on the fly. We are using them to avoid users having
                to create a database to run the sample. This is not something that should be used in production.
                See also the create=true line in the ariestrader-derby-ds blueprint meta data -->
                <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
                <property name="openjpa.jdbc.DBDictionary" value="oracle"/>
            </properties>
        </persistence-unit>
    </persistence>
    j'ai une classe mère que je ne veux pas persister et deux classes filles que je veux persister chacune dans une unité
    Code java : 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
    import javax.persistence.Column;
    import javax.persistence.Inheritance;
    import javax.persistence.InheritanceType;
    import javax.xml.bind.annotation.XmlRootElement;
    import javax.xml.bind.annotation.XmlType;
    // Je n'ai pas mis @Entity car je ne veux pas la persister 
    // mais j'ai mis les annotations pour que les classes héritières mappent sur les bons champs 
    @XmlType 
    @XmlRootElement
    @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) public class EventStore
    {   
        @Column(name = "EVENT_ID", unique = true, nullable = false)
        private int id;   
        @Column(name = "XID", columnDefinition = "VARCHAR2(200 BYTE)")
        private String xid;   
        @Column(name = "OBJECT_KEY", columnDefinition = "VARCHAR2(80 BYTE)")
        private String key;
        @Column(name = "OBJECT_NAME", columnDefinition = "VARCHAR2(40 BYTE)")
        private String name;
        @Column(name = "OBJECT_FUNCTION", columnDefinition = "VARCHAR2(40 BYTE)")
        private String function;
        @Column(name = "EVENT_PRIORITY", columnDefinition = "NUMBER(5,0)")
        private String priority;
        @Column(name = "EVENT_TIME", columnDefinition = "DATE")
        private String time;
        @Column(name = "EVENT_STATUS", columnDefinition = "NUMBER(5,0)")
        private String status;
        @Column(name = "EVENT_COMMENT", columnDefinition = "VARCHAR2(100 BYTE)")
        private String comment;   
        /**   
         *   
         */   
        public EventStore(){
            super();   
        }
        ...
    }
    Code java : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    @Entity @Table(name = "I48500_EVENTSTORE") 
    public class I48500EventStore extends EventStore
    {}
    Code java : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    @Entity @Table(name = "I48502_EVENTSTORE") 
    public class I48502EventStore extends EventStore
    {}
    Je m'attendais à ce que les tags
    Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
    <exclude-unlisted-classes>true</exclude-unlisted-classes>
    de mon persistance.xml sélectionne uniquement la classe définie dans l'unité de persistance.
    Mais en fait j'obtiens des Warnings qui m’informe qu'aucune classe ne peut être persisté.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    109  unit1  WARN   [main] openjpa.Enhance - Type "class fr.aphp.ati.eai.hermes.ng485.echange.model.EventStore" loaded by java.net.URLClassLoader@9319d9 has no metadata; enhancing as persistence aware. If you intended for "class fr.aphp.ati.eai.hermes.ng485.echange.model.EventStore" to be persistence-capable, then this means that OpenJPA could not find any metadata for "class fr.aphp.ati.eai.hermes.ng485.echange.model.EventStore". This can happen if the directory containing your metadata is not in your CLASSPATH, or if your metadata files are not named properly. See the documentation on metadata placement for more information.
    141  unit1  WARN   [main] openjpa.Runtime - Found no persistent property in "fr.aphp.ati.eai.hermes.ng485.echange.model.I48500EventStore"
    187  unit1  WARN   [main] openjpa.Runtime - Found no persistent property in "fr.aphp.ati.eai.hermes.ng485.echange.model.I48502EventStore"
     15  unit2  WARN   [main] openjpa.Enhance - Type "class fr.aphp.ati.eai.hermes.ng485.echange.model.EventStore" loaded by java.net.URLClassLoader@9319d9 has no metadata; enhancing as persistence aware. If you intended for "class fr.aphp.ati.eai.hermes.ng485.echange.model.EventStore" to be persistence-capable, then this means that OpenJPA could not find any metadata for "class fr.aphp.ati.eai.hermes.ng485.echange.model.EventStore". This can happen if the directory containing your metadata is not in your CLASSPATH, or if your metadata files are not named properly. See the documentation on metadata placement for more information.
     31  unit2  WARN   [main] openjpa.Runtime - Found no persistent property in "fr.aphp.ati.eai.hermes.ng485.echange.model.I48500EventStore" 
     31  unit2  WARN   [main] openjpa.Runtime - Found no persistent property in "fr.aphp.ati.eai.hermes.ng485.echange.model.I48502EventStore"
    j'ai lu et relu la doc, mais quelque chose m'échappe.
    J’ai donc essayé à tatons.
    Ajouter un @Entity à la classe mère ne change quasiment rien
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    141  unit1  WARN   [main] openjpa.Runtime - Found no persistent property in "fr.aphp.ati.eai.hermes.ng485.echange.model.I48500EventStore"
    187  unit1  WARN   [main] openjpa.Runtime - Found no persistent property in "fr.aphp.ati.eai.hermes.ng485.echange.model.I48502EventStore"
     31  unit2  WARN   [main] openjpa.Runtime - Found no persistent property in "fr.aphp.ati.eai.hermes.ng485.echange.model.I48500EventStore"
     31  unit2  WARN   [main] openjpa.Runtime - Found no persistent property in "fr.aphp.ati.eai.hermes.ng485.echange.model.I48502EventStore"
    Si une âme charitable pouvait m'éclairer de ses lumières, je lui en saurais gré.

    le but est donc de définir un @Entité qui peut être persisté dans deux tables différentes
    merci
    A+JYT

  2. #2
    Membre éprouvé
    Avatar de geforce
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Janvier 2010
    Messages
    1 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2010
    Messages : 1 055
    Par défaut
    Bonjour,

    Je suis tombé sur le même problème un jour et j'ai posté sur le forum voilà le lien : http://www.developpez.net/forums/d12...tence-xml-jpa/
    J'espère que ça pourra t'aider un peu.

  3. #3
    Membre émérite Avatar de slim
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Décembre 2002
    Messages
    938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2002
    Messages : 938
    Par défaut
    Bonjour,

    Je pense qu'il faut ajouter l'annotation

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    @MappedSuperclass
    public class ... { ... }
    Faites une recherche sur le forum et/ou sur internet et lisez la doc officielle avant de poser une question svp.
    et n'oubliez pas de lire les FAQ !
    FAQ Java et les cours et tutoriels Java
    Doc JAVA officielle
    AngularJS 1.x
    Angular 2

    Do it simple... and RTFM !

  4. #4
    Membre Expert
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2007
    Messages
    2 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Juin 2007
    Messages : 2 938
    Par défaut
    Citation Envoyé par slim Voir le message
    Bonjour,

    Je pense qu'il faut ajouter l'annotation

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    @MappedSuperclass
    public class ... { ... }
    Bonjour, il faut effectivement cette annotation dans la classe Mere qu'on ne désire pas persister, mais juste ses attributs qui le seront dans les classes filles.

  5. #5
    Expert confirmé
    Avatar de sekaijin
    Homme Profil pro
    Urbaniste
    Inscrit en
    Juillet 2004
    Messages
    4 205
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Urbaniste
    Secteur : Santé

    Informations forums :
    Inscription : Juillet 2004
    Messages : 4 205
    Par défaut
    merci à vous
    @MappedSuperclass
    est effectivement la formule magique et j'ai enfin trouvé la doc
    à son propos

    A+JYT

  6. #6
    Membre éprouvé
    Avatar de geforce
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Janvier 2010
    Messages
    1 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2010
    Messages : 1 055
    Par défaut
    Citation Envoyé par sekaijin Voir le message
    merci à vous
    @MappedSuperclass
    est effectivement la formule magique et j'ai enfin trouvé la doc
    à son propos

    A+JYT
    tu pourrais pas posté le lien de cette doc ?

    Merci

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

Discussions similaires

  1. Réponses: 2
    Dernier message: 09/06/2012, 16h33
  2. Je ne comprends pas les attributs XML
    Par ZeNoob dans le forum XML/XSL et SOAP
    Réponses: 2
    Dernier message: 02/05/2012, 19h31
  3. Réponses: 7
    Dernier message: 07/01/2008, 15h56
  4. [Deployment] persistence.xml pas détecté
    Par fisico dans le forum Glassfish et Payara
    Réponses: 1
    Dernier message: 24/08/2007, 21h56
  5. [ build.xml ] Je ne comprends pas qqchose
    Par n@n¤u dans le forum ANT
    Réponses: 6
    Dernier message: 04/05/2006, 11h53

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