我正在尝试将现有的Spring Data项目从Hibernate 4迁移到Hibernate5。该项目本身目前运行良好,但是某些依赖H2且以前运行良好的测试现在因此错误而中断:< / p>
Caused by: org.h2.jdbc.JdbcSQLException: Schema "SYS" not found; SQL statement:
select name from sys.sequences [90079-193]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
at org.h2.message.DbException.get(DbException.java:179)
at org.h2.message.DbException.get(DbException.java:155)
at org.h2.command.Parser.getSchema(Parser.java:679)
at org.h2.command.Parser.getSchema(Parser.java:685)
at org.h2.command.Parser.readTableFilter(Parser.java:1215)
at org.h2.command.Parser.parseSelectSimpleFromPart(Parser.java:1897)
at org.h2.command.Parser.parseSelectSimple(Parser.java:2045)
at org.h2.command.Parser.parseSelectSub(Parser.java:1891)
at org.h2.command.Parser.parseSelectUnion(Parser.java:1709)
at org.h2.command.Parser.parseSelect(Parser.java:1697)
at org.h2.command.Parser.parsePrepared(Parser.java:445)
at org.h2.command.Parser.parse(Parser.java:317)
at org.h2.command.Parser.parse(Parser.java:289)
at org.h2.command.Parser.prepareCommand(Parser.java:254)
at org.h2.engine.Session.prepareLocal(Session.java:561)
at org.h2.engine.Session.prepareCommand(Session.java:502)
at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1203)
at org.h2.jdbc.JdbcStatement.executeQuery(JdbcStatement.java:73)
at org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorLegacyImpl.extractMetadata(SequenceInformationExtractorLegacyImpl.java:42)
at org.hibernate.tool.schema.extract.internal.DatabaseInformationImpl.initializeSequences(DatabaseInformationImpl.java:65)
at org.hibernate.tool.schema.extract.internal.DatabaseInformationImpl.<init>(DatabaseInformationImpl.java:59)
at org.hibernate.tool.schema.internal.Helper.buildDatabaseInformation(Helper.java:132)
... 52 more
这是H2配置:
@Configuration
@Profile("h2")
public class H2Config implements DatabaseConfig {
@Override
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder()
.setName("h2test")
.setType(EmbeddedDatabaseType.H2)
.setScriptEncoding("UTF-8")
.build();
}
@Override
public Database databaseType() {
return Database.H2;
}
@Override
public boolean generateSchema() {
return true;
}
@Override
public Resource[] populateScripts() throws IOException {
return (new PathMatchingResourcePatternResolver())
.getResources("classpath:/bootstrap-sql/*.sql");
}
@Override
public Resource[] populateResources() throws IOException {
return (new PathMatchingResourcePatternResolver()
.getResources("classpath:/bootstrap-data/*.json"));
}
}
无效的可能解决方案:
尝试使用.setName("h2test;INIT=CREATE SCHEMA IF NOT EXISTS h2test;SCHEMA=h2test")
或类似名称设置和/或自动创建模式会导致有关该模式仍然不存在的错误,或者导致有关尝试查询不存在的sequences
表的错误。
Hibernate 5文档中建议尝试将项目@GeneratedValue
的格式更改为这种格式...
@GeneratedValue( generator = "custom-uuid" )
@GenericGenerator(
name = "custom-uuid",
strategy = "org.hibernate.id.UUIDGenerator",
parameters = {
@Parameter(
name = "uuid_gen_strategy_class",
value = "org.hibernate.id.uuid.CustomVersionOneStrategy"
)
}
)
...没什么区别。