2013-07-24 37 views
6

Tôi đang chạy thử nghiệm bằng cách sử dụng Arquillian, JBoss, JPA/Hibernate, H2 DB và Maven. Trong tệp persistence.xml thử nghiệm của tôi, tôi có:Hibernate SchemaExport không thể tạo lược đồ đầu tiên

<property name="hibernate.hbm2ddl.auto" value="create-drop" /> 
<property name="hibernate.show_sql" value="true" /> 

Hiện tại tôi có một lớp người dùng được ánh xạ tới bảng 'người dùng' thông qua chú thích Hibernate.

Mọi thứ gần như hoạt động. Vấn đề là Hibernate đang cố gắng thực hiện:

drop table my_schema.users if exists 

Nhưng lược đồ 'my_schema' không tồn tại nên nó không thành công (tôi đang chạy với DB trong bộ nhớ).

Làm cách nào để có được ngủ đông để thực thi bước 'tạo lược đồ my_schema' mà dường như nó bị quên?

Cập nhật: Các thông điệp tôi nhìn thấy từ Hibernate:


09:42:45,402 INFO [org.jboss.as.jpa] (MSC service thread 1-7) JBAS011402: Starting Persistence Unit Service 'test.war#ccmc' 
09:42:45,524 INFO [org.hibernate.annotations.common.Version] (MSC service thread 1-7) HCANN000001: Hibernate Commons Annotations {4.0.1.Final} 
09:42:45,532 INFO [org.hibernate.Version] (MSC service thread 1-7) HHH000412: Hibernate Core {4.0.1.Final} 
09:42:45,535 INFO [org.hibernate.cfg.Environment] (MSC service thread 1-7) HHH000206: hibernate.properties not found 
09:42:45,542 INFO [org.hibernate.cfg.Environment] (MSC service thread 1-7) HHH000021: Bytecode provider name : javassist 
09:42:45,572 INFO [org.hibernate.ejb.Ejb3Configuration] (MSC service thread 1-7) HHH000204: Processing PersistenceUnitInfo [ 
    name: ccmc 
    ...] 
09:42:45,739 INFO [org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator] (MSC service thread 1-7) HHH000130: Instantiating explicit connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider 
09:42:45,956 INFO [org.hibernate.dialect.Dialect] (MSC service thread 1-7) HHH000400: Using dialect: org.hibernate.dialect.H2Dialect 
09:42:45,962 WARN [org.hibernate.dialect.H2Dialect] (MSC service thread 1-7) HHH000431: Unable to determine H2 database version, certain features may not work 
09:42:45,965 INFO [org.hibernate.engine.jdbc.internal.LobCreatorBuilder] (MSC service thread 1-7) HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4 
09:42:45,973 INFO [org.hibernate.engine.transaction.internal.TransactionFactoryInitiator] (MSC service thread 1-7) HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory 
09:42:45,976 INFO [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (MSC service thread 1-7) HHH000397: Using ASTQueryTranslatorFactory 
09:42:46,003 INFO [org.hibernate.validator.util.Version] (MSC service thread 1-7) Hibernate Validator 4.2.0.Final 
09:42:46,269 INFO [org.hibernate.tool.hbm2ddl.SchemaExport] (MSC service thread 1-7) HHH000227: Running hbm2ddl schema export 
09:42:46,275 INFO [stdout] (MSC service thread 1-7) Hibernate: drop table ccmc.users if exists 
09:42:46,283 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] (MSC service thread 1-7) HHH000389: Unsuccessful: drop table ccmc.users if exists 
09:42:46,283 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] (MSC service thread 1-7) Schema "CCMC" not found; SQL statement: 
drop table ccmc.users if exists [90079-161] 
09:42:46,284 INFO [stdout] (MSC service thread 1-7) Hibernate: create table ccmc.users (user_id decimal(19,2) generated by default as identity, email varchar(100) not null unique, primary key (user_id)) 
09:42:46,285 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] (MSC service thread 1-7) HHH000389: Unsuccessful: create table ccmc.users (user_id decimal(19,2) generated by default as identity, email varchar(100) not null unique, primary key (user_id)) 
09:42:46,285 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] (MSC service thread 1-7) Schema "CCMC" not found; SQL statement: 
create table ccmc.users (user_id decimal(19,2) generated by default as identity, email varchar(100) not null unique, primary key (user_id)) [90079-161] 
09:42:46,286 INFO [org.hibernate.tool.hbm2ddl.SchemaExport] (MSC service thread 1-7) HHH000230: Schema export complete 
+0

bạn có thể đăng stacktraces lỗi không? – Hippoom

+0

chắc chắn ... không có bất kỳ stacktraces cho mỗi se, nhưng tôi đăng đầu ra máy chủ. tất nhiên sau đó khi tôi cố gắng làm điều gì đó, như lưu một người dùng mới có stacktraces vì ​​bảng 'người dùng' không tồn tại, nhưng điều đó được mong đợi ... – lostdorje

+0

Điều gì xảy ra nếu bạn thay đổi "tạo-thả" thành "tạo"? – Hippoom

Trả lời

16

Tôi tìm thấy câu trả lời trong SO Question khác.

Khi xác định URL kết nối với DB, điều này cần phải được thêm: "INIT = CREATE SCHEMA IF NOT EXISTS". Vì vậy, URL đầy đủ trong tệp persistence.xml trông giống như:

<connection-url>jdbc:h2:mem:test-db;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS ccmc</connection-url> 

nơi ccmc là tên của lược đồ được tạo. Param DB_CLOSE_DELAY không liên quan đến vấn đề và có thể được bỏ qua một cách an toàn về vấn đề này.

Các vấn đề liên quan