H2 In-Memory-DatenbankproblemJava

Java-Forum
Anonymous
 H2 In-Memory-Datenbankproblem

Post by Anonymous »

Ich habe ein seltsames Problem mit der H2-In-Memory-Datenbank in meinen Spring JUNIT-Tests. Wenn ich eine Entität bestrichen, wird die ID erfolgreich festgelegt (was auf die persistische Operation hinweist). Wenn ich jedoch versuche, die Entität unmittelbar danach abzurufen, erhalte ich einen Fehler "Tabelle nicht gefunden".

Code: Select all

@Test
public void testEntityPersistence() {
Long entityId = 1L;
String category = "category1";

// This works - entity is persisted and ID is set
MyEntity entity = repo.saveEntity(entityId, category, 1,
LocalTime.now().minusMinutes(10), LocalTime.now().plusHours(2), "Asia/Kolkata");

// This fails with "Table not found" error
List entities = entityService.getEntities(entityId, category);
}
< /code>
Umgebungsdetails < /p>
app.datasource.driverClassName = org.h2.Driver
app.datasource.url = jdbc:h2:mem:test;DB_CLOSE_DELAY=-1
app.datasource.username = sa
app.datasource.password =

app.hibernate.database = H2
app.hibernate.dialect = org.hibernate.dialect.H2Dialect
app.hibernate.hbm2ddl.auto = update
app.hibernate.jdbc.time_zone = UTC
app.hibernate.show_sql=false
What I've tried:

[*]Adding DB_CLOSE_DELAY=-1 to the H2 URL (already present)
[*]Setting hibernate.hbm2ddl.auto = create-drop instead of update
Ensuring the test is running in a Transaktion < /li>
< /ul>
Protokoll: < /p>

Code: Select all

Hibernate: drop table if exists my_entity CASCADE
Hibernate: create table my_entity (id bigint not null, created_at timestamp, updated_at timestamp, version integer, category varchar(255) not null, day integer not null, from_time time not null, to_time time not null, entity_id bigint not null, zone_id varchar(255) not null, primary key (id))
Hibernate: create index entityCategoryIndex on my_entity (entity_id, category)
Hibernate: insert into my_entity (created_at, updated_at, version, category, day, from_time, to_time, entity_id, zone_id, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
ERROR SqlExceptionHelper Table "MY_ENTITY" not found; SQL statement:
insert into my_entity (created_at, updated_at, version, category, day, from_time, to_time, entity_id, zone_id, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [42102-220]
Hibernate: drop table if exists my_entity CASCADE
Wenn ich die Version 1.4.x verwende, kommt dieser Fehler nicht, sondern für Versionen 2. X.y ist es da.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post