gpt4 book ai didi

java - Hibernate Table 未找到、MappingException 和 AssertionException

转载 作者:行者123 更新时间:2023-11-30 02:22:32 24 4
gpt4 key购买 nike

我尝试使用 Hibernate 映射现有的 Postgresql 数据库,虽然我没有将每个子类的继承添加到 Hibernate,但它已经可以工作了

这是父类(super class)

@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

它运行平稳,并且映射其他表格,包括位置。

我已经在这个问题上投入了几天时间 ^^

抱歉英语很奇怪,这不是我的外语:)

各位晚上好

铁轨列车

最佳答案

我遇到了同样的问题(或非常相似的问题)。

Hibernate 5.2.17.Final + PostgreSQL + Inheritance.JOINED.

通过从映射中删除“catalog”属性解决了这个问题。尝试更换

@Table(name = "place", schema = "public", catalog = "dbp")

@Table(name = "place", schema = "public")

希望这有帮助。

关于java - Hibernate Table 未找到、MappingException 和 AssertionException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46411824/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com