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

Autres SGBD Discussion :

Problème sur h2 : ajout d'une séquence


Sujet :

Autres SGBD

  1. #1
    Membre régulier
    Problème sur h2 : ajout d'une séquence
    Bonjour a tous, voici mon ddl
    Code :Sélectionner tout -Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    CREATE SEQUENCE monSchemas._SEQ INCREMENT 1 START 1;
    CREATE TABLE monSchemas.maTable 
    (
       id bigint nextval.('schemas._SEQ')PRIMARY KEY NOT NULL,
       IdUnit bigint DEFAULT 0 NOT NULL);





    nners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
    Caused by: org.hibernate.exception.SQLGrammarException: Cannot open connection
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52)
    at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449)
    at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
    at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:161)
    at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1700)
    at org.hibernate.loader.Loader.doQuery(Loader.java:801)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
    at org.hibernate.loader.Loader.doList(Loader.java:2542)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
    at org.hibernate.loader.Loader.list(Loader.java:2271)
    at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:316)
    at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1842)
    at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:165)
    at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:157)
    at com.odotrack.log.dao.hibernate.NmeaLogHibernateDao$1.doInHibernate(NmeaLogHibernateDao.java:86)
    at com.odotrack.log.dao.hibernate.NmeaLogHibernateDao$1.doInHibernate(NmeaLogHibernateDao.java:1)
    at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411)
    ... 36 more
    Caused by: org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "
    CREATE TABLE monSchemas.maTable
    (
    id bigint NEXTVAL[*]['monSchemas._SEQ INCREMENT'] PRIMARY KEY NOT NULL,
    IDUNIT BIGINT DEFAULT 0 NOT NULL) "; expected "(, FOR, UNSIGNED, NOT, NULL, AS, DEFAULT, GENERATED, NOT, NULL, AUTO_INCREMENT, BIGSERIAL, SERIAL, IDENTITY, NULL_TO_DEFAULT, SEQUENCE, SELECTIVITY, COMMENT, CONSTRAINT, PRIMARY, UNIQUE, NOT, NULL, CHECK, REFERENCES, ,, )"; SQL statement:

    CREATE TABLE monSchemas.maTable
    (
    id bigint NEXTVAL['monSchemas._SEQ INCREMENT'] PRIMARY KEY NOT NULL,
    IdUnit bigint DEFAULT 0 NOT NULL) [42001-194]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
    at org.h2.message.DbException.getSyntaxError(DbException.java:205)
    at org.h2.command.Parser.getSyntaxError(Parser.java:539)
    at org.h2.command.Parser.read(Parser.java:3242)
    at org.h2.command.Parser.readIfMore(Parser.java:887)
    at org.h2.command.Parser.parseCreateTable(Parser.java:6119)
    at org.h2.command.Parser.parseCreate(Parser.java:4302)
    at org.h2.command.Parser.parsePrepared(Parser.java:364)
    at org.h2.command.Parser.parse(Parser.java:319)
    at org.h2.command.Parser.parse(Parser.java:295)
    at org.h2.command.Parser.prepare(Parser.java:240)
    at org.h2.engine.Session.prepare(Session.java:529)
    at org.h2.engine.Session.prepare(Session.java:516)
    at org.h2.command.dml.RunScriptCommand.execute(RunScriptCommand.java:74)
    at org.h2.command.dml.RunScriptCommand.update(RunScriptCommand.java:57)
    at org.h2.command.CommandContainer.update(CommandContainer.java:101)
    at org.h2.command.Command.executeUpdate(Command.java:258)
    at org.h2.command.CommandList.update(CommandList.java:42)
    at org.h2.command.CommandList.executeRemaining(CommandList.java:36)
    at org.h2.command.CommandList.update(CommandList.java:43)
    at org.h2.command.Command.executeUpdate(Command.java:258)
    at org.h2.engine.Engine.openSession(Engine.java:224)
    at org.h2.engine.Engine.createSessionAndValidate(Engine.java:154)
    at org.h2.engine.Engine.createSession(Engine.java:137)
    at org.h2.engine.Engine.createSession(Engine.java:27)
    at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:354)
    at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:116)
    at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:100)
    at org.h2.Driver.connect(Driver.java:69)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:208)
    at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:153)
    at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:144)
    at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:196)
    at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:159)
    at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:87)
    at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
    ... 51 more



    j'arrive pas a utilise ma sequence en h2 .
    Une personne peut m aider svp merci d avance

  2. #2
    Modérateur

    Ne serait-ce pas plutôt ainsi : id bigint DEFAULT nextval.('schemas._SEQ')PRIMARY KEY NOT NULL,
    Philippe Leménager. Ingénieur d'étude à l'École Nationale Supérieure de Formation de l'Enseignement Agricole. Autoentrepreneur.
    Mon ancien blog sur la conception des BDD, le langage SQL, le PHP... et mon nouveau blog sur les mêmes sujets.
    « Ce que l'on conçoit bien s'énonce clairement, et les mots pour le dire arrivent aisément ». (Nicolas Boileau)
    À la maison comme au bureau, j'utilise la suite Linux Mageïa !

  3. #3
    Membre régulier
    negatif ca me donne ceci
    Caused by: org.hibernate.exception.SQLGrammarException: Cannot open connection
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52)
    at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449)
    at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
    at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:161)
    at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1700)
    at org.hibernate.loader.Loader.doQuery(Loader.java:801)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
    at org.hibernate.loader.Loader.doList(Loader.java:2542)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
    at org.hibernate.loader.Loader.list(Loader.java:2271)
    at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:316)
    at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1842)
    at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:165)
    at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:157)
    at com.odotrack.log.dao.hibernate.NmeaLogHibernateDao$1.doInHibernate(NmeaLogHibernateDao.java:86)
    at com.odotrack.log.dao.hibernate.NmeaLogHibernateDao$1.doInHibernate(NmeaLogHibernateDao.java:1)
    at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411)
    ... 36 more
    Caused by: org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "
    CREATE TABLE schemas.maTable
    (
    id BIGINT DEFAULT NEXTVAL.([*]'schemas._SEQ') PRIMARY KEY NOT NULL,
    IDUNIT BIGINT DEFAULT 0 NOT NULL,) "; expected "identifier"; SQL statement:

    CREATE TABLE schemas.maTable
    (
    id bigint DEFAULT nextval.('schemas._SEQ') PRIMARY KEY NOT NULL,
    IdUnit bigint DEFAULT 0 NOT NULL) [42001-194]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
    at org.h2.message.DbException.getSyntaxError(DbException.java:205)
    at org.h2.command.Parser.readColumnIdentifier(Parser.java:3231)
    at org.h2.command.Parser.readTermObjectDot(Parser.java:2727)
    at org.h2.command.Parser.readTerm(Parser.java:2853)
    at org.h2.command.Parser.readFactor(Parser.java:2374)
    at org.h2.command.Parser.readSum(Parser.java:2361)
    at org.h2.command.Parser.readConcat(Parser.java:2331)
    at org.h2.command.Parser.readCondition(Parser.java:2166)
    at org.h2.command.Parser.readAnd(Parser.java:2138)
    at org.h2.command.Parser.readExpression(Parser.java:2130)
    at org.h2.command.Parser.parseColumnForTable(Parser.java:4012)
    at org.h2.command.Parser.parseCreateTable(Parser.java:6053)
    at org.h2.command.Parser.parseCreate(Parser.java:4302)
    at org.h2.command.Parser.parsePrepared(Parser.java:364)
    at org.h2.command.Parser.parse(Parser.java:319)
    at org.h2.command.Parser.parse(Parser.java:291)
    at org.h2.command.Parser.prepare(Parser.java:240)
    at org.h2.engine.Session.prepare(Session.java:529)
    at org.h2.engine.Session.prepare(Session.java:516)
    at org.h2.command.dml.RunScriptCommand.execute(RunScriptCommand.java:74)
    at org.h2.command.dml.RunScriptCommand.update(RunScriptCommand.java:57)
    at org.h2.command.CommandContainer.update(CommandContainer.java:101)
    at org.h2.command.Command.executeUpdate(Command.java:258)
    at org.h2.command.CommandList.update(CommandList.java:42)
    at org.h2.command.CommandList.executeRemaining(CommandList.java:36)
    at org.h2.command.CommandList.update(CommandList.java:43)
    at org.h2.command.Command.executeUpdate(Command.java:258)
    at org.h2.engine.Engine.openSession(Engine.java:224)
    at org.h2.engine.Engine.createSessionAndValidate(Engine.java:154)
    at org.h2.engine.Engine.createSession(Engine.java:137)
    at org.h2.engine.Engine.createSession(Engine.java:27)
    at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:354)
    at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:116)
    at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:100)
    at org.h2.Driver.connect(Driver.java:69)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:208)
    at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:153)
    at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:144)
    at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:196)
    at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:159)
    at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:87)
    at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
    ... 51 more
    pas sur que les sequences fonctionne vraiment avec H2

  4. #4
    Modérateur

    Je ne l'avais pas vu lors de ma première réponse mais n'y a t-il pas contradiction entre ceci : CREATE SEQUENCE monSchemas._SEQ et cela : nextval.('schemas._SEQ') ?

    Et donc je corrige ma première réponse ainsi : id bigint DEFAULT nextval.('monSchemas._SEQ')PRIMARY KEY NOT NULL,
    Philippe Leménager. Ingénieur d'étude à l'École Nationale Supérieure de Formation de l'Enseignement Agricole. Autoentrepreneur.
    Mon ancien blog sur la conception des BDD, le langage SQL, le PHP... et mon nouveau blog sur les mêmes sujets.
    « Ce que l'on conçoit bien s'énonce clairement, et les mots pour le dire arrivent aisément ». (Nicolas Boileau)
    À la maison comme au bureau, j'utilise la suite Linux Mageïa !