我尝试使用Hibernate映射现有的Postgresql数据库,但是我没有将每个子类的继承添加到Hibernate
这是超类
@Entity
@Table(name = "place", schema = "public", catalog = "dbp")
@Inheritance(strategy = InheritanceType.JOINED)
public class PlaceEntity {
private long id;
private String name;
private String url;
// private CityEntity cityById;
private ContinentEntity continentById;
private CountryEntity countryById;
这是子类
@Entity
@Table(name = "city", schema = "public", catalog = "dbp")
@PrimaryKeyJoinColumn(name = "cityid", referencedColumnName = "id")
public class CityEntity extends PlaceEntity{ //WHEN I ADD extends PlaceEntity , THE ERROR OCCURES
private Long cityid;
private Long ispartof;
//private PlaceEntity placeByCityid;
private CountryEntity countryByIspartof;
private Collection<PersonEntity> peopleByCityid;
private Collection<UniversityEntity> universitiesByCityid;
然后Intellij通过以下异常:
INFO: HHH000270: Type registration [java.util.UUID] overrides previous :org.hibernate.type.UUIDBinaryType@63a12c68
Sep 25, 2017 6:56:11 PM org.hibernate.AssertionFailure <init>
ERROR: HHH000099: an assertion failure occurred (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session): org.hibernate.AssertionFailure: Table dbprak24.public.place not found
Sep 25, 2017 6:56:11 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop
INFO: HHH10001008: Cleaning up connection pool [jdbc:postgresql://localhost:5432/dbprak24]
java.lang.ExceptionInInitializerError
at Main.<clinit>(Main.java:22)
Caused by: org.hibernate.MappingException: Could not instantiate persister org.hibernate.persister.entity.JoinedSubclassEntityPersister
at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:112)
at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:77)
at org.hibernate.metamodel.internal.MetamodelImpl.initialize(MetamodelImpl.java:128)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:297)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:452)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:710)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:726)
at Main.<clinit>(Main.java:20)
Caused by: org.hibernate.AssertionFailure: Table dbprak24.public.place not found
at org.hibernate.persister.entity.AbstractEntityPersister.getTableId(AbstractEntityPersister.java:5231)
at org.hibernate.persister.entity.JoinedSubclassEntityPersister.<init>(JoinedSubclassEntityPersister.java:433)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:96)
... 7 more
Exception in thread "main"
Process finished with exit code 1
我已经搜索了相关问题,但找不到任何解决方案。 如果有人能帮助我,我会很高兴:)
总是当我删除
extends PlaceEntity
它运行顺畅,它映射了als Tables,包括在内。
我已经在这个问题上投入了几天^^
抱歉奇怪的英语,这不是我的外语:)。
晚上的好伙伴
Eisenbahnplatte
答案 0 :(得分:1)
我遇到过同样的问题(或类似的问题)。
Hibernate 5.2.17.Final + PostgreSQL + Inheritance.JOINED。
通过从映射中删除“catalog”属性来解决它。尝试替换
@Table(name = "place", schema = "public", catalog = "dbp")
与
@Table(name = "place", schema = "public")
希望这有帮助。