2

I'm trying to run a test that uses H2 in-memory database and hibernate. But I get the following error during context start-up:

Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "CREATE TABLE ANIMAL (ID BIGINT NOT NULL, CREATIONDATE DATETIME, CREATOR VARCHAR(255), LASTMODIFICATION DATETIME, LASTMODIFIEDBY VARCHAR(255), VERSION BIGINT, ALLERGIES VARCHAR(255), ANAMNESIS VARCHAR(255), BREED VARCHAR(255), COMMENT VARCHAR(255), DATEOFBIRTH DATETIME, DECEASED BIT NOT NULL, DIET VARCHAR(255), HUSBANDRY VARCHAR(255), IDCODE VARCHAR(255), NAME VARCHAR(255), SEX INTEGER, WEIGHT FLOAT, FK_OWNER BIGINT, TAXONOMY_ID BIGINT, PRIMARY KEY (ID)) ENGINE=[*]MYISAM"; expected "identifier";

What am I doing wrong? Here is application.properties file:

jdbc.driverClassName=org.h2.Driver
jdbc.url=jdbc:h2:mem:myDb;DB_CLOSE_DELAY=-1

hibernate.dialect=org.hibernate.dialect.H2Dialect
hibernate.hbm2ddl.auto=create

The same error is repeating for all databases that hibernate tries to create:

org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "CREATE TABLE HIBERNATE_SEQUENCE (NEXT_VAL BIGINT) ENGINE=[*]MYISAM"; expected "identifier"

3
  • In the creation script do you have each instruction in a single line? Commented Oct 14, 2020 at 11:31
  • yes, the script is actually generated by Hibernate Commented Oct 14, 2020 at 11:33
  • Add Animal entity class. Commented Oct 14, 2020 at 12:11

1 Answer 1

1

So at the end issue was in configuration file where I had wrong lines:

Properties additionalProperties() {
    Properties properties = new Properties();
    properties.setProperty("hibernate.hbm2ddl.auto", "create-drop");
    properties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");

    return properties;
}

changed it with:

properties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto"));
properties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect"));

And all started working fine

Sign up to request clarification or add additional context in comments.

1 Comment

Are you using Spring?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.