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

Hibernate Java Discussion :

DDL Bizare a la création d'un schema


Sujet :

Hibernate Java

  1. #1
    Membre extrêmement actif
    Avatar de kedare
    Homme Profil pro
    SRE
    Inscrit en
    Juillet 2005
    Messages
    1 549
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Espagne

    Informations professionnelles :
    Activité : SRE

    Informations forums :
    Inscription : Juillet 2005
    Messages : 1 549
    Par défaut DDL Bizare a la création d'un schema
    Hello,
    j'ai un petit probleme, Hibernate me créer un DDL bizare pour crée le schema, voila les infos :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    INFO: Running hbm2ddl schema export
    24 sept. 2008 20:50:15 org.hibernate.tool.hbm2ddl.SchemaExport execute
    INFO: exporting generated schema to database
    24 sept. 2008 20:50:15 org.hibernate.tool.hbm2ddl.SchemaExport create
    GRAVE: Unsuccessful: create table Products (id integer generated by default as identity (start with 1), shortname varchar(255), longname varchar(255), barcode varchar(255), buyprice float, sellprice float, taxe float, primary key (id))
    24 sept. 2008 20:50:15 org.hibernate.tool.hbm2ddl.SchemaExport create
    GRAVE: ERROR: syntax error at or near "generated"
    24 sept. 2008 20:50:15 org.hibernate.tool.hbm2ddl.SchemaExport execute
    INFO: schema export complete
    et le fichier de configuration hibernate :
    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
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
    <hibernate-configuration>
        <session-factory>
            <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
            <property name="hibernate.connection.url">jdbc:postgresql://localhost/kedare</property>
            <property name="hibernate.connection.username">kedare</property>
            <property name="hibernate.connection.password">____</property>
     
                <!-- JDBC connection pool (use the built-in) -->
            <property name="connection.pool_size">1</property>
     
            <!-- SQL dialect -->
            <property name="dialect">org.hibernate.dialect.HSQLDialect</property>
     
            <!-- Enable Hibernate's automatic session context management -->
            <property name="current_session_context_class">thread</property>
     
            <!-- Disable the second-level cache  -->
            <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
     
            <!-- Echo all executed SQL to stdout -->
            <property name="show_sql">true</property>
     
            <!-- Drop and re-create the database schema on startup -->
            <property name="hbm2ddl.auto">create</property>
     
            <mapping resource="jstock/Product.hbm.xml"/>
        </session-factory>
    </hibernate-configuration>
    Impossible de savoir pourquoi j'ai cette requête bizarre, qui bien sure n'est pas compatible postgresql,
    voila j'espère que vous pourrez m'aider,
    merci

  2. #2
    Membre très actif Avatar de ZeRevo
    Inscrit en
    Avril 2007
    Messages
    302
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Avril 2007
    Messages : 302
    Par défaut
    Le dialect pour postgres est org.hibernate.dialect.PostgreSQLDialect

  3. #3
    Membre extrêmement actif
    Avatar de kedare
    Homme Profil pro
    SRE
    Inscrit en
    Juillet 2005
    Messages
    1 549
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Espagne

    Informations professionnelles :
    Activité : SRE

    Informations forums :
    Inscription : Juillet 2005
    Messages : 1 549
    Par défaut
    Oh ok, merci
    Quand doit-on utiliser le HSQL?

    par contre j'ai cette erreur maintenant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    INFO: schema export complete
    Hibernate: select nextval ('hibernate_sequence')
    Exception in thread "main" org.hibernate.HibernateException: identifier of an instance of jstock.Product was altered from 1 to 0

  4. #4
    Membre très actif Avatar de ZeRevo
    Inscrit en
    Avril 2007
    Messages
    302
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Avril 2007
    Messages : 302
    Par défaut
    hsql c'est pour une base de données hsqldb, elle est utilisé pour un besoin de bdd embarquée.

    tu utilises une séquence postgres, est-ce que cette séquence existe bien dans ta bdd ? il doit y avoir une désynchro dans tes données en bdd, supprimes les et recommence.

  5. #5
    Membre extrêmement actif
    Avatar de kedare
    Homme Profil pro
    SRE
    Inscrit en
    Juillet 2005
    Messages
    1 549
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Espagne

    Informations professionnelles :
    Activité : SRE

    Informations forums :
    Inscription : Juillet 2005
    Messages : 1 549
    Par défaut
    rien a faire, j'ai beau utiliser une nouvelle base de donnée ou la vider j'ai toujours cette erreur :/

  6. #6
    Membre très actif Avatar de ZeRevo
    Inscrit en
    Avril 2007
    Messages
    302
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Avril 2007
    Messages : 302
    Par défaut
    on peut voir le fichier de mapping ?

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

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

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Par défaut
    identifier of an instance of jstock.Product was altered from 1 to 0


    Faudrait voir le stacktrace complet, mais l'id passe de 0 à 1. Soit c'est toi qui modifie l'id manuellement après avoir persisté l'instance, ce qui est interdit, soit la db, lors de l'insert alter l'id.

  8. #8
    Membre extrêmement actif
    Avatar de kedare
    Homme Profil pro
    SRE
    Inscrit en
    Juillet 2005
    Messages
    1 549
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Espagne

    Informations professionnelles :
    Activité : SRE

    Informations forums :
    Inscription : Juillet 2005
    Messages : 1 549
    Par défaut
    voila le fichier de mapping et la classe, puis le trackback, au passage comment faire pour ne pas avoir a mettre un setId ? vu que je ne veut pas qu'on puisse le modifier, mais il gueule si j'en met pas, donc j'en ai mis un qui ne fait rien...

    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
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <hibernate-mapping>
        <class name="jstock.Product" table="Products">
            <id column="id" name="id">
                <generator class="native"/>
            </id>
            <property column="shortname" name="shortName" type="string"/>
            <property column="longname" name="longName" type="string"/>
            <property column="barcode" name="barCode" type="string"/>
            <property column="buyprice" name="buyPrice" type="float"/>
            <property column="sellprice" name="sellPrice" type="float"/>
            <property column="taxe" name="taxe" type="float"/>
        </class>
    </hibernate-mapping>
    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
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    package jstock;
     
    /**
     *
     * @author kedare
     */
    public class Product {
        private int id;
        private String shortName;
        private String longName;
        private String barCode;
        private float buyPrice;
        private float sellPrice;
        private float taxe;
     
        int getId() { return id; }
        String getShortName() { return shortName; }
        String getLongName() { return longName; }
        String getBarCode() { return barCode; }
        float getBuyPrice() { return buyPrice; }
        float getSellPrice() { return sellPrice; }
        float getTaxe() { return taxe; }
     
        void setId(int id) {}
        void setShortName(String shortName) {this.shortName = shortName;}
        void setLongName(String longName) {this.longName = longName;}
        void setBarCode(String barCode) {this.barCode = barCode;}
        void setBuyPrice(float buyPrice) { this.buyPrice = buyPrice;}
        void setSellPrice(float sellPrice) {this.sellPrice = sellPrice;}
        void setTaxe(float taxe) { this.taxe = taxe;}
     
    }
    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
    run:
    25 sept. 2008 18:18:02 org.hibernate.cfg.annotations.Version <clinit>
    INFO: Hibernate Annotations 3.4.0.GA
    25 sept. 2008 18:18:02 org.hibernate.cfg.Environment <clinit>
    INFO: Hibernate 3.3.1.GA
    25 sept. 2008 18:18:02 org.hibernate.cfg.Environment <clinit>
    INFO: hibernate.properties not found
    25 sept. 2008 18:18:02 org.hibernate.cfg.Environment buildBytecodeProvider
    INFO: Bytecode provider name : javassist
    25 sept. 2008 18:18:02 org.hibernate.cfg.Environment <clinit>
    INFO: using JDK 1.4 java.sql.Timestamp handling
    25 sept. 2008 18:18:02 org.hibernate.annotations.common.Version <clinit>
    INFO: Hibernate Commons Annotations 3.1.0.GA
    25 sept. 2008 18:18:02 org.hibernate.cfg.Configuration configure
    INFO: configuring from resource: /hibernate.cfg.xml
    25 sept. 2008 18:18:02 org.hibernate.cfg.Configuration getConfigurationInputStream
    INFO: Configuration resource: /hibernate.cfg.xml
    25 sept. 2008 18:18:02 org.hibernate.cfg.Configuration addResource
    INFO: Reading mappings from resource : jstock/Product.hbm.xml
    25 sept. 2008 18:18:02 org.hibernate.cfg.Configuration doConfigure
    INFO: Configured SessionFactory: null
    25 sept. 2008 18:18:02 org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
    INFO: Mapping class: jstock.Product -> Products
    25 sept. 2008 18:18:02 org.hibernate.cfg.AnnotationConfiguration secondPassCompile
    INFO: Hibernate Validator not found: ignoring
    25 sept. 2008 18:18:02 org.hibernate.connection.DriverManagerConnectionProvider configure
    INFO: Using Hibernate built-in connection pool (not for production use!)
    25 sept. 2008 18:18:02 org.hibernate.connection.DriverManagerConnectionProvider configure
    INFO: Hibernate connection pool size: 1
    25 sept. 2008 18:18:02 org.hibernate.connection.DriverManagerConnectionProvider configure
    INFO: autocommit mode: false
    25 sept. 2008 18:18:03 org.hibernate.connection.DriverManagerConnectionProvider configure
    INFO: using driver: org.postgresql.Driver at URL: jdbc:postgresql://localhost/kedare2
    25 sept. 2008 18:18:03 org.hibernate.connection.DriverManagerConnectionProvider configure
    INFO: connection properties: {user=kedare, password=****}
    25 sept. 2008 18:18:04 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: RDBMS: PostgreSQL, version: 8.2.5
    25 sept. 2008 18:18:04 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: JDBC driver: PostgreSQL Native Driver, version: PostgreSQL 8.3 JDBC3 with SSL (build 603)
    25 sept. 2008 18:18:04 org.hibernate.dialect.Dialect <init>
    INFO: Using dialect: org.hibernate.dialect.PostgreSQLDialect
    25 sept. 2008 18:18:04 org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
    INFO: Using default transaction strategy (direct JDBC transactions)
    25 sept. 2008 18:18:04 org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
    INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
    25 sept. 2008 18:18:04 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Automatic flush during beforeCompletion(): disabled
    25 sept. 2008 18:18:04 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Automatic session close at end of transaction: disabled
    25 sept. 2008 18:18:04 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: JDBC batch size: 15
    25 sept. 2008 18:18:04 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: JDBC batch updates for versioned data: disabled
    25 sept. 2008 18:18:04 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Scrollable result sets: enabled
    25 sept. 2008 18:18:04 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: JDBC3 getGeneratedKeys(): disabled
    25 sept. 2008 18:18:04 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Connection release mode: auto
    25 sept. 2008 18:18:04 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Default batch fetch size: 1
    25 sept. 2008 18:18:04 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Generate SQL with comments: disabled
    25 sept. 2008 18:18:04 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Order SQL updates by primary key: disabled
    25 sept. 2008 18:18:04 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Order SQL inserts for batching: disabled
    25 sept. 2008 18:18:04 org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
    INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
    25 sept. 2008 18:18:04 org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
    INFO: Using ASTQueryTranslatorFactory
    25 sept. 2008 18:18:04 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Query language substitutions: {}
    25 sept. 2008 18:18:04 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: JPA-QL strict compliance: disabled
    25 sept. 2008 18:18:04 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Second-level cache: enabled
    25 sept. 2008 18:18:04 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Query cache: disabled
    25 sept. 2008 18:18:04 org.hibernate.cfg.SettingsFactory createRegionFactory
    INFO: Cache region factory : org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge
    25 sept. 2008 18:18:04 org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge <init>
    INFO: Cache provider: org.hibernate.cache.NoCacheProvider
    25 sept. 2008 18:18:04 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Optimize cache for minimal puts: disabled
    25 sept. 2008 18:18:04 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Structured second-level cache entries: disabled
    25 sept. 2008 18:18:04 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Echoing all SQL to stdout
    25 sept. 2008 18:18:04 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Statistics: disabled
    25 sept. 2008 18:18:04 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Deleted entity synthetic identifier rollback: disabled
    25 sept. 2008 18:18:04 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Default entity-mode: pojo
    25 sept. 2008 18:18:04 org.hibernate.cfg.SettingsFactory buildSettings
    INFO: Named query checking : enabled
    25 sept. 2008 18:18:04 org.hibernate.search.Version <clinit>
    INFO: Hibernate Search 3.0.1.GA
    25 sept. 2008 18:18:04 org.hibernate.impl.SessionFactoryImpl <init>
    INFO: building session factory
    25 sept. 2008 18:18:04 org.hibernate.impl.SessionFactoryObjectFactory addInstance
    INFO: Not binding factory to JNDI, no JNDI name configured
    25 sept. 2008 18:18:04 org.hibernate.tool.hbm2ddl.SchemaExport execute
    INFO: Running hbm2ddl schema export
    25 sept. 2008 18:18:04 org.hibernate.tool.hbm2ddl.SchemaExport execute
    INFO: exporting generated schema to database
    25 sept. 2008 18:18:05 org.hibernate.tool.hbm2ddl.SchemaExport execute
    INFO: schema export complete
    Hibernate: select nextval ('hibernate_sequence')
    Exception in thread "main" org.hibernate.HibernateException: identifier of an instance of jstock.Product was altered from 1 to 0
            at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:81)
            at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:187)
            at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:143)
            at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:219)
            at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99)
            at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:49)
            at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
            at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:365)
            at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
            at jstock.Main.main(Main.java:32)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 5 seconds)

  9. #9
    Membre très actif Avatar de ZeRevo
    Inscrit en
    Avril 2007
    Messages
    302
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Avril 2007
    Messages : 302
    Par défaut
    Dans 99% des cas tu ne dois pas définir l'id, c'est le sgbd qui s'en occupe.
    Tu as mis generator="native" mais postgres utilise une séquence pour gérer l'avancement d'un serial.

    Il faut que tu précises le nom de ta séquence dans le fichier de mapping :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    <generator class="sequence">
    <param name="sequence">ma_sequence</param>
    </generator>

Discussions similaires

  1. [Doctrine] Création d'un schema.yml particulier
    Par sheva23 dans le forum PHP & Base de données
    Réponses: 5
    Dernier message: 19/05/2011, 14h19
  2. Réponses: 19
    Dernier message: 10/05/2010, 15h36
  3. Réponses: 2
    Dernier message: 16/10/2007, 09h42
  4. Création d'une Grille pour création d'un Schema
    Par ben_ghost dans le forum AWT/Swing
    Réponses: 2
    Dernier message: 15/10/2007, 16h08
  5. Réponses: 2
    Dernier message: 03/05/2007, 09h38

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