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

Persistance des données Java Discussion :

Problème de migration de XML vers les annotations


Sujet :

Persistance des données Java

  1. #1
    Membre émérite

    Homme Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2013
    Messages
    1 066
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Conseil

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 066
    Points : 2 569
    Points
    2 569
    Par défaut Problème de migration de XML vers les annotations
    Bonjour,

    Je souhaite migrer un projet, qui utilisent Hibernate 4.0 avec le mapping XML, pour évoluer vers un mapping avec des annotations.
    J’ai décidé un peu tard de passer aux annotations.
    Je reprends un vieux projet, et je souhaite retrouver la même chose qu’avec les EJB 3.
    C’est pourquoi je pense que ça vient de ma configuration.
    J’obtiens toujours le même message d’ ‘erreur.
    «2014-11-26T15:53:59.480+0100 ERROR user lacks privilege or object not found: FOO«

    J’ai beau chercher, je ne trouve pas.
    J’ai écrit une classe simple Foo.java et un code pour y accéder Teste Foo.java.
    Pour la configuration je passe par le code, au lieu de XML.

    Est-il possible de méllanger des classes avec des annotations et des configurations XML ?
    Je souhaite évoluer progressivement.
    Concernant les annotations faut-il utiliser celle de JPA ou d’hibernate ?

    Merci d’avance pour votre aide

    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
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
     
    @Entity
    public class Foo {
    	protected int id;
    	protected String name;
     
    	public Foo() {
    	}
     
    	@Id
    	@GeneratedValue(strategy = GenerationType.AUTO)
    	public int getId() {
    		return id;
    	}
     
    	public void setId(int id) {
    		this.id = id;
    	}
     
    	public String getName() {
    		return name;
    	}
     
    	public void setName(String name) {
    		this.name = name;
    	}
     
    	@Override
    	public String toString() {
    		return "Foo [id=" + id + ", name=" + name + ", getId()=" + getId()
    				+ ", getName()=" + getName() + ", getClass()=" + getClass()
    				+ ", hashCode()=" + hashCode() + ", toString()="
    				+ super.toString() + "]";
    	}
    }
     
     
    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import org.hibernate.Transaction;
    import org.hibernate.cfg.AnnotationConfiguration;
    import org.hibernate.tool.hbm2ddl.SchemaUpdate;
     
    public class TestFoo {
    	public static void main(String[] args) {
    		AnnotationConfiguration configuration = new AnnotationConfiguration();
     
    		configuration
    				.setProperty("hibernate.dialect",
    						"org.hibernate.dialect.HSQLDialect")
    				.setProperty("hibernate.connection.driver_class",
    						"org.hsqldb.jdbcDriver")
    				.setProperty("hibernate.connection.url",
    						"jdbc:hsqldb:file:local/foo.hsql")
    				.setProperty("hibernate.connection.username", "sa")
    				.setProperty("hibernate.connection.password", "");
     
    		configuration.setProperty("hibernate.connection.pool_size", "4");
    		configuration.setProperty("hibernate.connection.autocommit", "true");
    		configuration.setProperty("hibernate.cache.provider_class",
    				"org.hibernate.cache.NoCacheProvider");
    		configuration.setProperty("hibernate.transaction.factory_class",
    				"org.hibernate.transaction.JDBCTransactionFactory");
    		configuration.setProperty("hibernate.current_session_context_class",
    				"thread");
     
    		new SchemaUpdate(configuration);
     
    		configuration.addAnnotatedClass(Foo.class);
     
    		SessionFactory sessionFactory = configuration.buildSessionFactory();
     
    		Session session = sessionFactory.openSession();
     
    		Transaction transaction = session.beginTransaction();
     
    		Foo foo = new Foo();
    		foo.setName("Une autre foo");
     
    		session.persist(foo);
     
    		transaction.commit();
     
    		session.close();
    	}
    }
    Consultez mes articles sur l'accessibilité numérique :

    Comment rendre son application SWING accessible aux non voyants
    Créer des applications web accessibles à tous

    YES WE CAN BLANCHE !!!

    Rappelez-vous que Google est le plus grand aveugle d'Internet...
    Plus c'est accessible pour nous, plus c'est accessible pour lui,
    et meilleur sera votre score de référencement !

  2. #2
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

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

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    tu peux afficher la stacktrace complète?

    Et oui, tu peux mixer annotation et xml dans un même factory, ça permet d'ailleur de faciliter la transition des gros projets. Par contre, pour une entité donnée, c'est xml ou annotation, pas les deux.

  3. #3
    Membre émérite

    Homme Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2013
    Messages
    1 066
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Conseil

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 066
    Points : 2 569
    Points
    2 569
    Par défaut
    Désolé j'ai oublié Le plus important.
    Le problème c'est, qui ne trouve pas, ma classe et il ne génère pas la table SQL.
    Pour l'instant j'ai activé la modification automatique de schéma, donc je pensais qu'il me la crérait
    Ca va me jouer des tours, quand je vais migrer mes classes une à une vers les annotations.

    Il y a plein de messages avant l'erreur.

    nov. 27, 2014 6:48:53 AM org.hibernate.annotations.common.Version <clinit>
    INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
    nov. 27, 2014 6:48:53 AM org.hibernate.Version logVersion
    INFO: HHH000412: Hibernate Core {4.1.9.Final}
    nov. 27, 2014 6:48:53 AM org.hibernate.cfg.Environment <clinit>
    INFO: HHH000206: hibernate.properties not found
    nov. 27, 2014 6:48:53 AM org.hibernate.cfg.Environment buildBytecodeProvider
    INFO: HHH000021: Bytecode provider name : javassist
    nov. 27, 2014 6:48:53 AM org.hibernate.dialect.Dialect <init>
    INFO: HHH000400: Using dialect: org.hibernate.dialect.HSQLDialect
    nov. 27, 2014 6:48:53 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
    INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
    nov. 27, 2014 6:48:53 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
    INFO: HHH000115: Hibernate connection pool size: 4
    nov. 27, 2014 6:48:53 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
    INFO: HHH000006: Autocommit mode: true
    nov. 27, 2014 6:48:53 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
    INFO: HHH000401: using driver [org.hsqldb.jdbcDriver] at URL [jdbc:hsqldb:file:local/foo.hsql]
    nov. 27, 2014 6:48:53 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
    INFO: HHH000046: Connection properties: {user=sa, password=****, autocommit=true}
    2014-11-27T06:48:54.468+0100 WARN HSEARCH000075: Configuration setting hibernate.search.lucene_version was not specified, using LUCENE_CURRENT.

    *** ici **

    2014-11-27T06:48:55.229+0100 WARN SQL Error: -5501, SQLState: 42501
    2014-11-27T06:48:55.229+0100 ERROR user lacks privilege or object not found: FOO
    Exception in thread "main" org.hibernate.exception.SQLGrammarException: user lacks privilege or object not found: FOO
    at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:82)
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
    at org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler.continueInvocation(ConnectionProxyHandler.java:146)
    at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
    at com.sun.proxy.$Proxy5.prepareStatement(Unknown Source)
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$2.doPrepare(StatementPreparerImpl.java:105)
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:166)
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareStatement(StatementPreparerImpl.java:103)
    at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.prepare(IdentityGenerator.java:89)
    at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:55)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2936)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3447)
    at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:81)
    at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362)
    at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:203)
    at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:183)
    at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:167)
    at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:320)
    at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:287)
    at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:193)
    at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:126)
    at org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:208)
    at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:151)
    at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:78)
    at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:843)
    at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:818)
    at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:822)
    at TestFoo.main(TestFoo.java:43)
    Caused by: java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: FOO
    at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
    at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
    at org.hsqldb.jdbc.JDBCPreparedStatement.<init>(Unknown Source)
    at org.hsqldb.jdbc.JDBCConnection.prepareStatement(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler.continueInvocation(ConnectionProxyHandler.java:138)
    ... 25 more
    Caused by: org.hsqldb.HsqlException: user lacks privilege or object not found: FOO
    at org.hsqldb.error.Error.error(Unknown Source)
    at org.hsqldb.error.Error.error(Unknown Source)
    at org.hsqldb.SchemaManager.getTable(Unknown Source)
    at org.hsqldb.ParserDQL.readTableName(Unknown Source)
    at org.hsqldb.ParserDQL.readRangeVariableForDataChange(Unknown Source)
    at org.hsqldb.ParserDML.compileInsertStatement(Unknown Source)
    at org.hsqldb.ParserCommand.compilePart(Unknown Source)
    at org.hsqldb.ParserCommand.compileStatement(Unknown Source)
    at org.hsqldb.Session.compileStatement(Unknown Source)
    at org.hsqldb.StatementManager.compile(Unknown Source)
    at org.hsqldb.Session.execute(Unknown Source)
    ... 32 more
    Consultez mes articles sur l'accessibilité numérique :

    Comment rendre son application SWING accessible aux non voyants
    Créer des applications web accessibles à tous

    YES WE CAN BLANCHE !!!

    Rappelez-vous que Google est le plus grand aveugle d'Internet...
    Plus c'est accessible pour nous, plus c'est accessible pour lui,
    et meilleur sera votre score de référencement !

  4. #4
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

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

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    Citation Envoyé par CoderInTheDark Voir le message
    Pour l'instant j'ai activé la modification automatique de schéma, donc je pensais qu'il me la crérait
    Ca va me jouer des tours, quand je vais migrer mes classes une à une vers les annotations.
    Les annotations n'ont rien à voir dans l'histoire, hibernate a besoin soit que les tables existent, soit d'être autorisé à les créer. Visiblement ici, la table n'existe pas et tu n'as pas demandé dans la configuration à hibernate de créer le schéma.

    Soit tu demande à hibernate de créer automatiquement

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    		configuration.setProperty("hibernate.hbm2ddl.auto",
    				"create");
    Soit, vu que tu joue avec la class SchemaUpdate, tu n'oublie pas d'appeler la méthode execute dessus.

  5. #5
    Membre émérite

    Homme Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2013
    Messages
    1 066
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Conseil

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 066
    Points : 2 569
    Points
    2 569
    Par défaut
    Merci,
    La table a été crée, mais les objets ne 'sont pas sauvés.
    Il n'y a pas de message d'erreur dans la console.
    Tout semble normal.
    Après le save ou persist, il a bien un id généré à 1.
    (...)
    INFO: HHH000046: Connection properties: {user=sa, password=****, autocommit=true}
    2014-11-27T16:36:00.352+0100 WARN HSEARCH000075: Configuration setting hibernate.search.lucene_version was not specified, using LUCENE_CURRENT.
    Foo [id=1, name=Une autre foo, getId()=1, getName()=Une autre foo, getClass()=class Foo, hashCode()=841262455, toString()=Foo@3224a577]

    Il n'y a rien sur le insert.

    Concernant le schéma, je ne tiens pas à la deuxième méthode.
    Je vais prendre la première le code sera plus homogène.
    En plus j'ai l'impression, que dans mon projet principal j'utilise les deux méthodes.
    Il s'agit d'une portion que j'ai oublié de supprimer lors d'une révision.
    Cordialement
    Fabrice
    Consultez mes articles sur l'accessibilité numérique :

    Comment rendre son application SWING accessible aux non voyants
    Créer des applications web accessibles à tous

    YES WE CAN BLANCHE !!!

    Rappelez-vous que Google est le plus grand aveugle d'Internet...
    Plus c'est accessible pour nous, plus c'est accessible pour lui,
    et meilleur sera votre score de référencement !

  6. #6
    Membre chevronné Avatar de jeffray03
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2008
    Messages
    1 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 501
    Points : 2 120
    Points
    2 120
    Par défaut
    Salut
    comment est ton fichier de configuration?

    eric

  7. #7
    Membre émérite

    Homme Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2013
    Messages
    1 066
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Conseil

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 066
    Points : 2 569
    Points
    2 569
    Par défaut
    Bonjour,

    Je n'ai pas de fichier de configuration général.
    Je passe par le code uniquement.
    Et je cherche à me débarrasser des fichiers de mapping XML.
    Sauf erreur de ma part à par pour Log4j et le mapping, je n'ai pas de fichiers de configuration.
    Tout est dans le code.
    Je veux utiliser une configuration générale de développement pour HsqlDb puis Mys`Sql/`.
    Dans l'application on pourra travailler avec plusieurs bases.
    Je changerai la partie BDD, en fonction des préférences des utilisateurs
    J'ai activé le show sql et le update pour, que la base s'adapte aux changements ., car ma partie model change beaucoup

    J'ai modifié le code, et la configuration est dedans.
    Le fichier model Foo.plus haut java n'a pas changé

    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import org.hibernate.Transaction;
    import org.hibernate.cfg.AnnotationConfiguration;

    public class TestFoo {
    public static void main(String[] args) {
    AnnotationConfiguration configuration = new AnnotationConfiguration();

    configuration
    .setProperty("hibernate.dialect",
    "org.hibernate.dialect.HSQLDialect")
    .setProperty("hibernate.connection.driver_class",
    "org.hsqldb.jdbcDriver")
    .setProperty("hibernate.connection.url",
    "jdbc:hsqldb:file:local/foo.hsql")
    .setProperty("hibernate.connection.username", "sa")
    .setProperty("hibernate.connection.password", "");
    configuration.setProperty("hibernate.connection.pool_size", "4");
    configuration.setProperty("hibernate.connection.autocommit", "true");
    configuration.setProperty("hibernate.cache.provider_class",
    "org.hibernate.cache.NoCacheProvider");
    configuration.setProperty("hibernate.transaction.factory_class",
    "org.hibernate.transaction.JDBCTransactionFactory");

    configuration.setProperty("hibernate.hbm2ddl.auto", "update");
    configuration.setProperty("connection.show_sql", "true");
    configuration.setProperty("hibernate.current_session_context_class",
    "thread");


    configuration.addAnnotatedClass(Foo.class);

    SessionFactory sessionFactory = configuration.buildSessionFactory();

    Session session = sessionFactory.openSession();

    Transaction transaction = session.beginTransaction();

    Foo foo = new Foo();
    foo.setName("Une autre foo");

    session.save(foo);

    System.out.println(foo);


    transaction.commit();

    session.close();
    }
    }

    Le résultat de la console
    nov. 29, 2014 1:37:40 PM org.hibernate.annotations.common.Version <clinit>
    INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
    nov. 29, 2014 1:37:40 PM org.hibernate.Version logVersion
    INFO: HHH000412: Hibernate Core {4.1.9.Final}
    nov. 29, 2014 1:37:40 PM org.hibernate.cfg.Environment <clinit>
    INFO: HHH000206: hibernate.properties not found
    nov. 29, 2014 1:37:40 PM org.hibernate.cfg.Environment buildBytecodeProvider
    INFO: HHH000021: Bytecode provider name : javassist
    nov. 29, 2014 1:37:40 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
    INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
    nov. 29, 2014 1:37:40 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
    INFO: HHH000115: Hibernate connection pool size: 4
    nov. 29, 2014 1:37:40 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
    INFO: HHH000006: Autocommit mode: true
    nov. 29, 2014 1:37:40 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
    INFO: HHH000401: using driver [org.hsqldb.jdbcDriver] at URL [jdbc:hsqldb:file:local/foo.hsql]
    nov. 29, 2014 1:37:40 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
    INFO: HHH000046: Connection properties: {user=sa, password=****, autocommit=true}
    2014-11-29T13:37:40.938+0100 WARN HSEARCH000075: Configuration setting hibernate.search.lucene_version was not specified, using LUCENE_CURRENT.
    Foo [id=1, name=Une autre foo, getId()=1, getName()=Une autre foo, getClass()=class Foo, hashCode()=483797427, toString()=Foo@1cd629b3]

    Je dois avouer, que je ne suis pas sûr de tous les paramètres.
    Là, la table a été créée , mais il n'y a pas d'insertion dans la table.
    J'ai vérifier les fichiers de ma base HSQL
    Consultez mes articles sur l'accessibilité numérique :

    Comment rendre son application SWING accessible aux non voyants
    Créer des applications web accessibles à tous

    YES WE CAN BLANCHE !!!

    Rappelez-vous que Google est le plus grand aveugle d'Internet...
    Plus c'est accessible pour nous, plus c'est accessible pour lui,
    et meilleur sera votre score de référencement !

  8. #8
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

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

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    Tu peux modifier ton code et nous dire ce que ça sort? Aussi, comment peux-tu dire qu'il n'y a rien dans la table, comment vérifie-tu? Ce n'est pas vérifié par ton code en tout cas. Tu est sur de regarder la même base?

    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
    Session session = sessionFactory.openSession();
     
    Transaction transaction = session.beginTransaction();
     
    Foo foo = new Foo();
    foo.setName("Une autre foo");
     
    session.save(foo);
     
    System.out.println(foo);
     
     
    transaction.commit();
     
    session.close();
     
    Session session = sessionFactory.openSession();
     
    System.out.println(session.createQuery('from Foo").list();
     
    session.createSQLQuery("SHUTDOWN").executeUpdate();

  9. #9
    Membre émérite

    Homme Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2013
    Messages
    1 066
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Conseil

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 066
    Points : 2 569
    Points
    2 569
    Par défaut
    Ca marche, je pense que c'est le execute.shutdown, qui manquait.

    Pour vérifier, j'allais dans le fichier hsql.script.
    Et en plus, dans la console, l'id de l'objet n'avançait pas, il restait à 1.

    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import org.hibernate.Transaction;
    import org.hibernate.cfg.AnnotationConfiguration;

    public class TestFoo {
    public static void main(String[] args) {
    AnnotationConfiguration configuration = new AnnotationConfiguration();

    configuration
    .setProperty("hibernate.dialect",
    "org.hibernate.dialect.HSQLDialect")
    .setProperty("hibernate.connection.driver_class",
    "org.hsqldb.jdbcDriver")
    .setProperty("hibernate.connection.url",
    "jdbc:hsqldb:file:local/foo.hsql")
    .setProperty("hibernate.connection.username", "sa")
    .setProperty("hibernate.connection.password", "");
    configuration.setProperty("hibernate.connection.pool_size", "4");
    configuration.setProperty("hibernate.connection.autocommit", "true");
    configuration.setProperty("hibernate.cache.provider_class",
    "org.hibernate.cache.NoCacheProvider");
    configuration.setProperty("hibernate.transaction.factory_class",
    "org.hibernate.transaction.JDBCTransactionFactory");

    configuration.setProperty("hibernate.hbm2ddl.auto", "update");
    configuration.setProperty("connection.show_sql", "true");
    configuration.setProperty("hibernate.current_session_context_class",
    "thread");


    configuration.addAnnotatedClass(Foo.class);

    SessionFactory sessionFactory = configuration.buildSessionFactory();

    Session session = sessionFactory.openSession();


    Foo foo = new Foo();
    foo.setName("Une autre foo");

    Transaction transaction = session.beginTransaction();

    session.save(foo);

    System.out.println(foo);

    transaction.commit();

    session.createSQLQuery("SHUTDOWN").executeUpdate();
    session.close();
    }
    }

    Voila le fichier hsql.script, après l'exécution du bon code.
    J'ai peur de dire une bêtise, mais, quand on oublie de faire le execute shutdown, ce n'est pas trop grave avec MySql, mais avec les bases en fichiers ça ne pardone pas.
    J'ai déja eut le problème.
    SET DATABASE UNIQUE NAME HSQLDB49EC370394
    SET DATABASE GC 0
    SET DATABASE DEFAULT RESULT MEMORY ROWS 0
    SET DATABASE EVENT LOG LEVEL 0
    SET DATABASE SQL NAMES FALSE
    SET DATABASE SQL REGULAR NAMES TRUE
    SET DATABASE SQL REFERENCES FALSE
    SET DATABASE SQL SIZE TRUE
    SET DATABASE SQL TYPES FALSE
    SET DATABASE SQL TDC DELETE TRUE
    SET DATABASE SQL TDC UPDATE TRUE
    SET DATABASE SQL TRANSLATE TTI TYPES TRUE
    SET DATABASE SQL CONCAT NULLS TRUE
    SET DATABASE SQL NULLS FIRST TRUE
    SET DATABASE SQL UNIQUE NULLS TRUE
    SET DATABASE SQL CONVERT TRUNCATE TRUE
    SET DATABASE SQL AVG SCALE 0
    SET DATABASE SQL DOUBLE NAN TRUE
    SET DATABASE SQL LONGVAR IS LOB FALSE
    SET DATABASE TRANSACTION CONTROL LOCKS
    SET DATABASE DEFAULT ISOLATION LEVEL READ COMMITTED
    SET DATABASE TRANSACTION ROLLBACK ON CONFLICT TRUE
    SET DATABASE TEXT TABLE DEFAULTS ''
    SET FILES WRITE DELAY 500 MILLIS
    SET FILES BACKUP INCREMENT TRUE
    SET FILES CACHE SIZE 10000
    SET FILES CACHE ROWS 50000
    SET FILES SCALE 32
    SET FILES LOB SCALE 32
    SET FILES DEFRAG 0
    SET FILES NIO TRUE
    SET FILES NIO SIZE 256
    SET FILES LOG TRUE
    SET FILES LOG SIZE 50
    CREATE USER SA PASSWORD DIGEST 'd41d8cd98f00b204e9800998ecf8427e'
    ALTER USER SA SET LOCAL TRUE
    CREATE SCHEMA PUBLIC AUTHORIZATION DBA
    SET SCHEMA PUBLIC
    CREATE MEMORY TABLE PUBLIC.FOO(ID INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL PRIMARY KEY,NAME VARCHAR(255))
    ALTER TABLE PUBLIC.FOO ALTER COLUMN ID RESTART WITH 6
    ALTER SEQUENCE SYSTEM_LOBS.LOB_ID RESTART WITH 1
    SET DATABASE DEFAULT INITIAL SCHEMA PUBLIC
    GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.YES_OR_NO TO PUBLIC
    GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.TIME_STAMP TO PUBLIC
    GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.CARDINAL_NUMBER TO PUBLIC
    GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.CHARACTER_DATA TO PUBLIC
    GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.SQL_IDENTIFIER TO PUBLIC
    GRANT DBA TO SA
    SET SCHEMA SYSTEM_LOBS
    INSERT INTO BLOCKS VALUES(0,2147483647,0)
    SET SCHEMA PUBLIC
    INSERT INTO FOO VALUES(1,'Une autre foo')
    INSERT INTO FOO VALUES(2,'Une autre foo')
    INSERT INTO FOO VALUES(3,'Une autre foo')
    INSERT INTO FOO VALUES(4,'Une autre foo')
    INSERT INTO FOO VALUES(5,'Une autre foo')


    Là il y a des insert

    Merci pour ton aide
    Consultez mes articles sur l'accessibilité numérique :

    Comment rendre son application SWING accessible aux non voyants
    Créer des applications web accessibles à tous

    YES WE CAN BLANCHE !!!

    Rappelez-vous que Google est le plus grand aveugle d'Internet...
    Plus c'est accessible pour nous, plus c'est accessible pour lui,
    et meilleur sera votre score de référencement !

  10. #10
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

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

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    Le execute shutdown permet à hsqdb de savoir qu'il doit s'arrêter. Là tu arrêtait simplement la jvm à la fin de ton main, et tant pis si il n'avait pas fini d'écrire. Mysql s'arrête lorsqu'il reçois des instructions de shutdown de l'OS, tu ne l'arrête pas après chaque arrêt de ton application java.

  11. #11
    Membre émérite

    Homme Profil pro
    Développeur informatique
    Inscrit en
    Octobre 2013
    Messages
    1 066
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Conseil

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 066
    Points : 2 569
    Points
    2 569
    Par défaut
    Merci je pense que c'est terminé.
    Par contre il aurait du me mettre une ligne insert dans la console.
    J'ai activé le show sql.
    Mais ca marche maintenant

    Cordialement
    Fabrice
    Consultez mes articles sur l'accessibilité numérique :

    Comment rendre son application SWING accessible aux non voyants
    Créer des applications web accessibles à tous

    YES WE CAN BLANCHE !!!

    Rappelez-vous que Google est le plus grand aveugle d'Internet...
    Plus c'est accessible pour nous, plus c'est accessible pour lui,
    et meilleur sera votre score de référencement !

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

Discussions similaires

  1. Problème de migration de MySQL vers SQL Server
    Par sovo dans le forum Langage SQL
    Réponses: 10
    Dernier message: 01/03/2013, 14h02
  2. Problème de redirection du Xml vers un site
    Par rugal201 dans le forum XML/XSL et SOAP
    Réponses: 3
    Dernier message: 12/07/2012, 01h24
  3. Problème de migration sunopsis V3 vers ODI
    Par lyten_ dans le forum ODI (ex-Sunopsis)
    Réponses: 5
    Dernier message: 04/11/2010, 14h24
  4. Réponses: 4
    Dernier message: 05/07/2009, 21h05
  5. Réponses: 8
    Dernier message: 05/07/2009, 12h45

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