2015-07-21 74 views
1

出于某种原因,Hibernate不创建类别表, 下面列出的代码 BaseEntityJPA /休眠(PSQL)不创建joinedtable

@MappedSuperclass 
public abstract class BaseEntity implements Serializable { 
    private static final long serialVersionUID = 1L; 
    @Id 
    @GeneratedValue(strategy = GenerationType.IDENTITY) 
    @Basic(optional = false) 
    @Column(name = "id", nullable = false, columnDefinition = "BIGINT UNSIGNED") 
    protected Long id; 
    @Column(name = "version") 
    @Version 
    private Long version; 

这里是从BaseEntity

继承其它两个类
@Entity 
@AttributeOverride(name = "id", column = @Column(name = "route_id", 
     nullable = false, columnDefinition = "BIGINT UNSIGNED")) 
public class Route extends BaseEntityAudit { 

    @ElementCollection 
    private Collection<Point> routePoints = new ArrayList<Point>(); 

    @OneToMany(cascade = CascadeType.ALL) 
    @JoinTable(name = "route_events") 
    private Collection<Event> routeEvents = new ArrayList<Event>(); 

    @OneToMany(cascade = CascadeType.ALL) 
    @JoinTable(name = "route_comments") 
    private Collection<Comment> comments = new ArrayList<Comment>(); 

@Entity 
@AttributeOverride(name = "id", column = @Column(name = "event_id", 
     nullable = false, columnDefinition = "BIGINT UNSIGNED")) 
public class Event extends BaseEntityAudit { 
    @Embedded 
    private Point point; 

    @OneToMany(cascade = CascadeType.ALL) 
    @JoinTable(name = "event_comments") 
    private Collection<Comment> comments = new ArrayList<Comment>(); 

persistence.xml中已将此属性名= “hibernate.hbm2ddl.auto” 值= “创建降”/ >

我的日志

Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: ERROR: relation "event_comments" does not exist 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: HHH000389: Unsuccessful: alter table event_comments drop constraint FK_11571d99a3cf411d9164940b877 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: ERROR: relation "event_comments" does not exist 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: HHH000389: Unsuccessful: alter table route_comments drop constraint FK_f8a59d97d3374c8385789cfba60 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: ERROR: relation "route_comments" does not exist 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: HHH000389: Unsuccessful: alter table route_comments drop constraint FK_513ae6d743c64d92ae0081d522d 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: ERROR: relation "route_comments" does not exist 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: HHH000389: Unsuccessful: alter table route_events drop constraint FK_65c26cfb67b342b081f210e4550 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: ERROR: relation "route_events" does not exist 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: HHH000389: Unsuccessful: alter table route_events drop constraint FK_feed651c8fdc4dc2bf274715db3 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: ERROR: relation "route_events" does not exist 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: HHH000389: Unsuccessful: create table Route_routePoints (Route_route_id BIGINT UNSIGNED not null, latitude float8, longitude float8) 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: ERROR: syntax error at or near "UNSIGNED" 
    Position: 55 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: HHH000389: Unsuccessful: create table event_comments (Event_event_id BIGINT UNSIGNED not null, comments_id BIGINT UNSIGNED not null) 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: ERROR: syntax error at or near "UNSIGNED" 
    Position: 52 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: HHH000389: Unsuccessful: create table route_comments (Route_route_id BIGINT UNSIGNED not null, comments_id BIGINT UNSIGNED not null) 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: ERROR: syntax error at or near "UNSIGNED" 
    Position: 52 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: HHH000389: Unsuccessful: create table route_events (Route_route_id BIGINT UNSIGNED not null, routeEvents_event_id BIGINT UNSIGNED not null) 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: ERROR: syntax error at or near "UNSIGNED" 
    Position: 50 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: HHH000389: Unsuccessful: alter table Route_routePoints add constraint FK_4e53fd400f6447a985cc918eca4 foreign key (Route_route_id) references Route 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: ERROR: relation "route_routepoints" does not exist 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: HHH000389: Unsuccessful: alter table event_comments add constraint UK_dd004f7aa4cc492a8fdbba97cb5 unique (comments_id) 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: ERROR: relation "event_comments" does not exist 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: HHH000389: Unsuccessful: alter table event_comments add constraint FK_4c93abd961304742bd47c55dcc1 foreign key (comments_id) references Comment 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: ERROR: relation "event_comments" does not exist 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: HHH000389: Unsuccessful: alter table event_comments add constraint FK_11571d99a3cf411d9164940b877 foreign key (Event_event_id) references Event 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: ERROR: relation "event_comments" does not exist 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: HHH000389: Unsuccessful: alter table route_comments add constraint UK_7fe905828f9d4dce993484493a7 unique (comments_id) 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: ERROR: relation "route_comments" does not exist 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: HHH000389: Unsuccessful: alter table route_comments add constraint FK_f8a59d97d3374c8385789cfba60 foreign key (comments_id) references Comment 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: ERROR: relation "route_comments" does not exist 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: HHH000389: Unsuccessful: alter table route_comments add constraint FK_513ae6d743c64d92ae0081d522d foreign key (Route_route_id) references Route 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: ERROR: relation "route_comments" does not exist 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: HHH000389: Unsuccessful: alter table route_events add constraint UK_42dd851c0e9a467e9911fab1caf unique (routeEvents_event_id) 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: ERROR: relation "route_events" does not exist 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: HHH000389: Unsuccessful: alter table route_events add constraint FK_65c26cfb67b342b081f210e4550 foreign key (routeEvents_event_id) references Event 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: ERROR: relation "route_events" does not exist 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: HHH000389: Unsuccessful: alter table route_events add constraint FK_feed651c8fdc4dc2bf274715db3 foreign key (Route_route_id) references Route 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport perform 
ERROR: ERROR: relation "route_events" does not exist 
Jul 22, 2015 2:42:39 AM org.hibernate.tool.hbm2ddl.SchemaExport execute 
INFO: HHH000230: Schema export complete 
Jul 22, 2015 2:42:39 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions 
WARN: SQL Error: 0, SQLState: 42P01 
Jul 22, 2015 2:42:39 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions 
ERROR: ERROR: relation "route_events" does not exist 
    Position: 13 

javax.persistence.RollbackException: Error while committing the transaction 
    at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:92) 
    at home.map.events.dao.daoImpl.DAOUtils.add(DAOUtils.java:15) 
    at home.map.events.dao.daoImpl.RouteDaoImpl.addRoute(RouteDaoImpl.java:16) 
    at home.map.events.dao.daoImpl.RouteDaoImplTest.start(RouteDaoImplTest.java:34) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) 
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) 
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24) 
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363) 
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137) 
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:78) 
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212) 
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140) 
Caused by: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute statement 
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1387) 
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1310) 
    at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:80) 
    ... 21 more 
Caused by: org.hibernate.exception.SQLGrammarException: could not execute statement 
    at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:123) 
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49) 
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125) 
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110) 
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:136) 
    at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:58) 
    at org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1256) 
    at org.hibernate.action.internal.CollectionRecreateAction.execute(CollectionRecreateAction.java:58) 
    at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:364) 
    at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:356) 
    at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:281) 
    at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:328) 
    at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52) 
    at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1234) 
    at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:404) 
    at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101) 
    at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:175) 
    at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:75) 
    ... 21 more 
Caused by: org.postgresql.util.PSQLException: ERROR: relation "route_events" does not exist 
    Position: 13 
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2198) 
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1927) 
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255) 
    at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:561) 
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:419) 
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:365) 
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:133) 
    ... 34 more 

当我检查PG管理员错过了表,如route_events不存在。 感谢您的帮助

回答