【发布时间】:2015-06-27 20:27:45
【问题描述】:
当 Hibernate 在 DB 中创建架构时,我有以下输出:
21:22:25,518 INFO [stdout] (ServerService Thread Pool -- 13) Hibernate:
21:22:25,518 INFO [stdout] (ServerService Thread Pool -- 13) alter table Contacto
21:22:25,518 INFO [stdout] (ServerService Thread Pool -- 13) drop
21:22:25,518 INFO [stdout] (ServerService Thread Pool -- 13) foreign key FK_5jh2jf636mhuh77q4hwl1i2w0
21:22:25,519 INFO [stdout] (ServerService Thread Pool -- 50) Hibernate:
21:22:25,519 INFO [stdout] (ServerService Thread Pool -- 50) alter table Contacto
21:22:25,519 INFO [stdout] (ServerService Thread Pool -- 50) drop
21:22:25,519 INFO [stdout] (ServerService Thread Pool -- 50) foreign key FK_5jh2jf636mhuh77q4hwl1i2w0
21:22:25,587 INFO [stdout] (ServerService Thread Pool -- 13) Hibernate:
21:22:25,587 INFO [stdout] (ServerService Thread Pool -- 13) drop table if exists Contacto
21:22:25,596 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 50) HHH000389: Unsuccessful: alter table Contacto drop foreign key FK_5jh2jf636mhuh77q4hwl1i2w0
21:22:25,596 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 50) Can't DROP 'FK_5jh2jf636mhuh77q4hwl1i2w0'; check that column/key exists
21:22:25,597 INFO [stdout] (ServerService Thread Pool -- 50) Hibernate:
21:22:25,597 INFO [stdout] (ServerService Thread Pool -- 50) drop table if exists Contacto
21:22:25,600 INFO [stdout] (ServerService Thread Pool -- 13) Hibernate:
21:22:25,600 INFO [stdout] (ServerService Thread Pool -- 13) drop table if exists Usuario
21:22:25,600 INFO [stdout] (ServerService Thread Pool -- 50) Hibernate:
21:22:25,601 INFO [stdout] (ServerService Thread Pool -- 50) drop table if exists Usuario
21:22:25,604 INFO [stdout] (ServerService Thread Pool -- 13) Hibernate:
21:22:25,604 INFO [stdout] (ServerService Thread Pool -- 13) create table Contacto (
21:22:25,604 INFO [stdout] (ServerService Thread Pool -- 13) id integer not null,
21:22:25,605 INFO [stdout] (ServerService Thread Pool -- 13) email varchar(255),
21:22:25,605 INFO [stdout] (ServerService Thread Pool -- 13) nombre varchar(255),
21:22:25,605 INFO [stdout] (ServerService Thread Pool -- 13) telefono varchar(255),
21:22:25,605 INFO [stdout] (ServerService Thread Pool -- 13) usuario_cuenta varchar(255),
21:22:25,605 INFO [stdout] (ServerService Thread Pool -- 13) primary key (id)
21:22:25,605 INFO [stdout] (ServerService Thread Pool -- 13) )
21:22:25,606 INFO [stdout] (ServerService Thread Pool -- 50) Hibernate:
21:22:25,606 INFO [stdout] (ServerService Thread Pool -- 50) create table Contacto (
21:22:25,606 INFO [stdout] (ServerService Thread Pool -- 50) id integer not null,
21:22:25,606 INFO [stdout] (ServerService Thread Pool -- 50) email varchar(255),
21:22:25,606 INFO [stdout] (ServerService Thread Pool -- 50) nombre varchar(255),
21:22:25,606 INFO [stdout] (ServerService Thread Pool -- 50) telefono varchar(255),
21:22:25,607 INFO [stdout] (ServerService Thread Pool -- 50) usuario_cuenta varchar(255),
21:22:25,607 INFO [stdout] (ServerService Thread Pool -- 50) primary key (id)
21:22:25,607 INFO [stdout] (ServerService Thread Pool -- 50) )
21:22:25,625 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 50) HHH000389: Unsuccessful: create table Contacto (id integer not null, email varchar(255), nombre varchar(255), telefono varchar(255), usuario_cuenta varchar(255), primary key (id))
21:22:25,625 INFO [stdout] (ServerService Thread Pool -- 13) Hibernate:
21:22:25,625 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 50) Table 'contacto' already exists
21:22:25,626 INFO [stdout] (ServerService Thread Pool -- 13) create table Usuario (
21:22:25,626 INFO [stdout] (ServerService Thread Pool -- 13) cuenta varchar(255) not null,
21:22:25,626 INFO [stdout] (ServerService Thread Pool -- 13) apellidos varchar(255),
21:22:25,627 INFO [stdout] (ServerService Thread Pool -- 13) email varchar(255),
21:22:25,627 INFO [stdout] (ServerService Thread Pool -- 13) nombre varchar(255),
21:22:25,627 INFO [stdout] (ServerService Thread Pool -- 13) password varchar(255),
21:22:25,628 INFO [stdout] (ServerService Thread Pool -- 13) primary key (cuenta)
21:22:25,628 INFO [stdout] (ServerService Thread Pool -- 13) )
21:22:25,628 INFO [stdout] (ServerService Thread Pool -- 50) Hibernate:
21:22:25,629 INFO [stdout] (ServerService Thread Pool -- 50) create table Usuario (
21:22:25,629 INFO [stdout] (ServerService Thread Pool -- 50) cuenta varchar(255) not null,
21:22:25,629 INFO [stdout] (ServerService Thread Pool -- 50) apellidos varchar(255),
21:22:25,629 INFO [stdout] (ServerService Thread Pool -- 50) email varchar(255),
21:22:25,630 INFO [stdout] (ServerService Thread Pool -- 50) nombre varchar(255),
21:22:25,630 INFO [stdout] (ServerService Thread Pool -- 50) password varchar(255),
21:22:25,630 INFO [stdout] (ServerService Thread Pool -- 50) primary key (cuenta)
21:22:25,630 INFO [stdout] (ServerService Thread Pool -- 50) )
21:22:25,639 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 50) HHH000389: Unsuccessful: create table Usuario (cuenta varchar(255) not null, apellidos varchar(255), email varchar(255), nombre varchar(255), password varchar(255), primary key (cuenta))
21:22:25,639 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 50) Table 'usuario' already exists
21:22:25,640 INFO [stdout] (ServerService Thread Pool -- 50) Hibernate:
21:22:25,640 INFO [stdout] (ServerService Thread Pool -- 50) alter table Contacto
21:22:25,640 INFO [stdout] (ServerService Thread Pool -- 50) add constraint FK_5jh2jf636mhuh77q4hwl1i2w0
21:22:25,641 INFO [stdout] (ServerService Thread Pool -- 50) foreign key (usuario_cuenta)
21:22:25,641 INFO [stdout] (ServerService Thread Pool -- 50) references Usuario (cuenta)
21:22:25,641 INFO [stdout] (ServerService Thread Pool -- 13) Hibernate:
21:22:25,641 INFO [stdout] (ServerService Thread Pool -- 13) alter table Contacto
21:22:25,642 INFO [stdout] (ServerService Thread Pool -- 13) add constraint FK_5jh2jf636mhuh77q4hwl1i2w0
21:22:25,642 INFO [stdout] (ServerService Thread Pool -- 13) foreign key (usuario_cuenta)
21:22:25,642 INFO [stdout] (ServerService Thread Pool -- 13) references Usuario (cuenta)
21:22:25,657 INFO [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 50) HHH000230: Schema export complete
21:22:25,664 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 13) HHH000389: Unsuccessful: alter table Contacto add constraint FK_5jh2jf636mhuh77q4hwl1i2w0 foreign key (usuario_cuenta) references Usuario (cuenta)
21:22:25,665 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 13) Can't write; duplicate key in table '#sql-2f4_20'
貌似应用有2个hibernate的Thread,这些Thread都在做同样的SQL语句(比如创建同样的表等等……)
发生了什么事?
提前致谢
【问题讨论】:
-
在我们查看您的一些代码之前很难说什么。
标签: java multithreading hibernate jpa