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 :

Configuration de persistence.xml en mode standalone (Java SE) avec Toplink


Sujet :

JPA Java

  1. #1
    Membre éclairé
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    802
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2007
    Messages : 802
    Points : 653
    Points
    653
    Par défaut Configuration de persistence.xml en mode standalone (Java SE) avec Toplink
    Bonjour,

    Je voudrais utiliser JPA en mode standalone avec toplink. J'ai utilisé cette doc pour renseigner le fichier persistence.xml :
    https://glassfish.dev.java.net/javae...e-support.html

    Voici donc mon fichier 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
     
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence xmlns="http://java.sun.com/xml/ns/persistence"
    	version="1.0">
    	<persistence-unit name="sample">
    		<provider>oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider</provider>
            <!-- All persistence classes must be listed -->
    		<class>beans.Address</class>
    		<class>beans.Person</class>
    		<properties>
                <!-- Provider-specific connection properties -->
    			<property name="toplink.jdbc.driver" value="<database driver>"/>
                <property name="toplink.jdbc.url" value="<database url>"/>
                <property name="toplink.jdbc.user" value="<user>"/>
                <property name="toplink.jdbc.password" value="<password>"/>
                <!-- Provider-specific settings -->
                <property name="toplink.logging.level" value="INFO"/>
            </properties>
        </persistence-unit>
    </persistence>
    Seulement je rencontre un erreur à l'exécution :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named sample: Provider named oracle.toplink.essentials.PersistenceProvider threw unexpected exception at create EntityManagerFactory: 
    oracle.toplink.essentials.exceptions.PersistenceUnitLoadingException
    Local Exception Stack: 
    Exception [TOPLINK-30005] (Oracle TopLink Essentials - 2.0.1 (Build b04-fcs (04/11/2008))): oracle.toplink.essentials.exceptions.PersistenceUnitLoadingException
    Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: sun.misc.Launcher$AppClassLoader@1ba34f2
    Internal Exception: Exception [TOPLINK-30004] (Oracle TopLink Essentials - 2.0.1 (Build b04-fcs (04/11/2008))): oracle.toplink.essentials.exceptions.PersistenceUnitLoadingException
    Exception Description: An exception was thrown while processing persistence.xml from URL: file:/home/hadrien/workspace/eclipse/hibernate/jpa/bin/
    Internal Exception: 
    (1. The value of attribute "value" associated with an element type "null" must not contain the '<' character.)
    Il semble que l'attribut value du tag property n'admet pas le caractère "<". Or, si j'enlève les brackets, j'ai une autre exception :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    Exception in thread "main" Local Exception Stack: 
    Exception [TOPLINK-4003] (Oracle TopLink Essentials - 2.0.1 (Build b04-fcs (04/11/2008))): oracle.toplink.essentials.exceptions.DatabaseException
    Exception Description: Configuration error.  Class [database driver] not found.
    Quelqu'un a-t-il déjà utilisé JPA avec Toplink ? Pouvez-vous m'aider à renseigner mon fichier persistence.xml ?

  2. #2
    Expert confirmé
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 274
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 274
    Points : 4 141
    Points
    4 141
    Par défaut
    A quoi cela: <database driver>, correspond ?
    Il faut fournir un nom de classe valide, celui de ton driver.

  3. #3
    Expert éminent
    Avatar de djo.mos
    Profil pro
    Inscrit en
    Octobre 2004
    Messages
    4 666
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2004
    Messages : 4 666
    Points : 7 679
    Points
    7 679
    Par défaut
    Salut,
    Dans les lignes suivantes:
    Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    <property name="toplink.jdbc.url" value="<database url>"/>
                <property name="toplink.jdbc.user" value="<user>"/>
                <property name="toplink.jdbc.password" value="<password>"/>

    Il faut remplacer les <...> par leurs valeurs correspondantes, genre:
    Code code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    <property name="toplink.jdbc.url" value="jdbc:hsqldb:file:test"/>
                <property name="toplink.jdbc.user" value="sa"/>
                <property name="toplink.jdbc.password" value=""/>

    Pour une BD de type HSQL par exemple ...

  4. #4
    Membre éclairé
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    802
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2007
    Messages : 802
    Points : 653
    Points
    653
    Par défaut
    Mais bien sûr, suis-je donc bête

    Bon maintenant j'ai un message d'erreur comme quoi la table n'existe pas. Est-ce qu'il existe avec toplink un paramètre du même genre qu'hibernate :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    <property name="hibernate.hbm2ddl.auto" value="create" />

  5. #5
    Expert éminent
    Avatar de djo.mos
    Profil pro
    Inscrit en
    Octobre 2004
    Messages
    4 666
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2004
    Messages : 4 666
    Points : 7 679
    Points
    7 679
    Par défaut
    Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    <property name="toplink.ddl-generation"
    				value="create-tables" />

    (Tu aurais pu retrouver ça avec une simple recherche )

  6. #6
    Membre éclairé
    Profil pro
    Inscrit en
    Juillet 2007
    Messages
    802
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2007
    Messages : 802
    Points : 653
    Points
    653
    Par défaut
    J'obtiens toujours un message d'erreur avec le message "table not found in statement". Pourtant, les logs laissent penser que mes tables ont bien été créees malgré quelques exceptions :
    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
    [TopLink Info]: 2008.09.26 11:08:43.069--ServerSession(28311783)--TopLink, version: Oracle TopLink Essentials - 2.0.1 (Build b04-fcs (04/11/2008))
    [TopLink Info]: 2008.09.26 11:08:43.359--Not able to detect platform for vendor name [HSQL Database Engine]. Defaulting to [oracle.toplink.essentials.platform.database.DatabasePlatform]. The database dialect used may not match with the database you are using. Please explicitly provide a platform using property toplink.platform.class.name.
    [TopLink Info]: 2008.09.26 11:08:43.429--ServerSession(28311783)--file:/home/hadrien/workspace/eclipse/hibernate/jpa/bin/-sample login successful
    [TopLink Warning]: 2008.09.26 11:08:43.458--ServerSession(28311783)--Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0.1 (Build b04-fcs (04/11/2008))): oracle.toplink.essentials.exceptions.DatabaseException
    Internal Exception: java.sql.SQLException: Wrong data type: NUMBER in statement [CREATE TABLE PERSON (ID NUMBER]
    Error Code: -16
    Call: CREATE TABLE PERSON (ID NUMBER(19) NOT NULL, FIRSTNAME VARCHAR(255), LASTNAME VARCHAR(255), ADDRESS_ID NUMBER(19), PRIMARY KEY (ID))
    Query: DataModifyQuery()
    [TopLink Warning]: 2008.09.26 11:08:43.463--ServerSession(28311783)--Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0.1 (Build b04-fcs (04/11/2008))): oracle.toplink.essentials.exceptions.DatabaseException
    Internal Exception: java.sql.SQLException: Wrong data type: NUMBER in statement [CREATE TABLE ADDRESS (ID NUMBER]
    Error Code: -16
    Call: CREATE TABLE ADDRESS (ID NUMBER(19) NOT NULL, NUMERO NUMBER(10), VILLE VARCHAR(255), RUE VARCHAR(255), CP NUMBER(10), PRIMARY KEY (ID))
    Query: DataModifyQuery()
    [TopLink Warning]: 2008.09.26 11:08:43.464--ServerSession(28311783)--Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0.1 (Build b04-fcs (04/11/2008))): oracle.toplink.essentials.exceptions.DatabaseException
    Internal Exception: java.sql.SQLException: Table not found: PERSON in statement [ALTER TABLE PERSON]
    Error Code: -22
    Call: ALTER TABLE PERSON ADD CONSTRAINT FK_PERSON_ADDRESS_ID FOREIGN KEY (ADDRESS_ID) REFERENCES ADDRESS (ID)
    Query: DataModifyQuery()
    [TopLink Warning]: 2008.09.26 11:08:43.466--ServerSession(28311783)--Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0.1 (Build b04-fcs (04/11/2008))): oracle.toplink.essentials.exceptions.DatabaseException
    Internal Exception: java.sql.SQLException: Wrong data type: NUMBER in statement [CREATE TABLE SEQUENCE (SEQ_NAME VARCHAR(50) NOT NULL, SEQ_COUNT NUMBER]
    Error Code: -16
    Call: CREATE TABLE SEQUENCE (SEQ_NAME VARCHAR(50) NOT NULL, SEQ_COUNT NUMBER(19), PRIMARY KEY (SEQ_NAME))
    Query: DataModifyQuery()
    [TopLink Warning]: 2008.09.26 11:08:43.470--ServerSession(28311783)--Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0.1 (Build b04-fcs (04/11/2008))): oracle.toplink.essentials.exceptions.DatabaseException
    Internal Exception: java.sql.SQLException: Table not found in statement [SELECT * FROM SEQUENCE WHERE SEQ_NAME = 'SEQ_GEN']
    Error Code: -22
    Call: SELECT * FROM SEQUENCE WHERE SEQ_NAME = 'SEQ_GEN'
    Query: DataReadQuery()
    tx.begin
    em.persist
    [TopLink Warning]: 2008.09.26 11:08:43.831--ClientSession(15774883)--Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0.1 (Build b04-fcs (04/11/2008))): oracle.toplink.essentials.exceptions.DatabaseException
    Internal Exception: java.sql.SQLException: Table not found in statement [UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?]
    Error Code: -22
    Call: UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?
    	bind => [50, SEQ_GEN]
    Query: DataModifyQuery()
    Exception in thread "main" Local Exception Stack: 
    Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0.1 (Build b04-fcs (04/11/2008))): oracle.toplink.essentials.exceptions.DatabaseException
    Internal Exception: java.sql.SQLException: Table not found in statement [UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?]
    Error Code: -22
    Call: UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?
    	bind => [50, SEQ_GEN]
    Query: DataModifyQuery()
    	at oracle.toplink.essentials.exceptions.DatabaseException.sqlException(DatabaseException.java:319)
    	at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:566)
    	at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:452)
    	at oracle.toplink.essentials.internal.sessions.AbstractSession.executeCall(AbstractSession.java:690)
    	at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:228)
    	at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:214)
    	at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.executeNoSelectCall(DatasourceCallQueryMechanism.java:257)
    	at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.executeNoSelect(DatasourceCallQueryMechanism.java:237)
    	at oracle.toplink.essentials.queryframework.DataModifyQuery.executeDatabaseQuery(DataModifyQuery.java:86)
    	at oracle.toplink.essentials.queryframework.DatabaseQuery.execute(DatabaseQuery.java:628)
    	at oracle.toplink.essentials.internal.sessions.AbstractSession.internalExecuteQuery(AbstractSession.java:1834)
    	at oracle.toplink.essentials.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:952)
    	at oracle.toplink.essentials.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:924)
    	at oracle.toplink.essentials.sequencing.QuerySequence.update(QuerySequence.java:344)
    	at oracle.toplink.essentials.sequencing.QuerySequence.updateAndSelectSequence(QuerySequence.java:283)
    	at oracle.toplink.essentials.sequencing.StandardSequence.getGeneratedVector(StandardSequence.java:96)
    	at oracle.toplink.essentials.sequencing.DefaultSequence.getGeneratedVector(DefaultSequence.java:168)
    	at oracle.toplink.essentials.sequencing.Sequence.getGeneratedVector(Sequence.java:281)
    	at oracle.toplink.essentials.internal.sequencing.SequencingManager$Preallocation_Transaction_NoAccessor_State.getNextValue(SequencingManager.java:420)
    	at oracle.toplink.essentials.internal.sequencing.SequencingManager.getNextValue(SequencingManager.java:848)
    	at oracle.toplink.essentials.internal.sequencing.ClientSessionSequencing.getNextValue(ClientSessionSequencing.java:110)
    	at oracle.toplink.essentials.internal.descriptors.ObjectBuilder.assignSequenceNumber(ObjectBuilder.java:240)
    	at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.assignSequenceNumber(UnitOfWorkImpl.java:355)
    	at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.registerNotRegisteredNewObjectForPersist(UnitOfWorkImpl.java:3260)
    	at oracle.toplink.essentials.internal.ejb.cmp3.base.RepeatableWriteUnitOfWork.registerNotRegisteredNewObjectForPersist(RepeatableWriteUnitOfWork.java:339)
    	at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist(UnitOfWorkImpl.java:3220)
    	at oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.persist(EntityManagerImpl.java:205)
    	at run.Main.persistence(Main.java:30)
    	at run.Main.main(Main.java:15)
    Caused by: java.sql.SQLException: Table not found in statement [UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?]
    	at org.hsqldb.jdbc.Util.throwError(Unknown Source)
    	at org.hsqldb.jdbc.jdbcPreparedStatement.<init>(Unknown Source)
    	at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
    	at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.prepareStatement(DatabaseAccessor.java:1162)
    	at oracle.toplink.essentials.internal.databaseaccess.DatabaseCall.prepareStatement(DatabaseCall.java:612)
    	at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:485)
    	... 27 more
    Voici mes classes :
    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
     
    @Entity
    public class Person {
    	@Id @GeneratedValue(strategy=GenerationType.AUTO)
    	private Long id;
     
    	private String firstname;
    	private String lastname;
     
    	@ManyToOne(cascade=CascadeType.ALL)
    	private Address address;
     
    	public Address getAddress() {
    		return address;
    	}
    	public void setAddress(Address address) {
    		this.address = address;
    	}
    	public String getFirstname() {
    		return firstname;
    	}
    	public void setFirstname(String firstname) {
    		this.firstname = firstname;
    	}
    	public String getLastname() {
    		return lastname;
    	}
    	public void setLastname(String lastname) {
    		this.lastname = lastname;
    	}
    	public Long getId() {
    		return id;
    	}
    	public String toString() {
    		return firstname + " " + lastname + " - " + address;
    	}
    }
     
    @Entity
    public class Address {
    	@Id @GeneratedValue(strategy=GenerationType.AUTO)
    	private long id;
     
    	private String rue;
    	private int numero;
    	private String ville;
    	private int cp;
     
    	public String getRue() {
    		return rue;
    	}
    	public void setRue(String rue) {
    		this.rue = rue;
    	}
    	public int getNumero() {
    		return numero;
    	}
    	public void setNumero(int numero) {
    		this.numero = numero;
    	}
    	public String getVille() {
    		return ville;
    	}
    	public void setVille(String ville) {
    		this.ville = ville;
    	}
    	public int getCp() {
    		return cp;
    	}
    	public void setCp(int cp) {
    		this.cp = cp;
    	}
    	public long getId() {
    		return id;
    	}
    	public String toString() {
    		return numero + ", " + rue + " - " + cp + " " + ville;
    	}
    }

Discussions similaires

  1. persistence.xml : java.net.MalformedURLException
    Par xirius2 dans le forum JPA
    Réponses: 0
    Dernier message: 24/01/2011, 19h31
  2. Problème de configuration de persistence.xml
    Par zied87 dans le forum Plateformes (Java EE, Jakarta EE, Spring) et Serveurs
    Réponses: 3
    Dernier message: 02/01/2011, 16h36
  3. Réponses: 0
    Dernier message: 12/02/2009, 12h39
  4. [EJB3 Entity] Configuration persistence.xml pour base PostGreSQL
    Par MaInR0 dans le forum Java EE
    Réponses: 1
    Dernier message: 09/01/2008, 11h19

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