Hibernate Table not found, MappingException and AssertionException

595 views Asked by At

I tried to map an existing Postgresql Database with Hibernate and it already worked while I didn't add Inheritances per Subclass to Hibernate

This is the superclass

@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;

And this is the subclass

@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;

Then Intellij throughs the following exception:

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

I already searched for related problems but couldn't find any solution. I'd be very glad if anyone could help me :)

Always when i delete

extends PlaceEntity

it runs smoothly and it maps als Tables, place included.

I already invested several days in that problem ^^

Sorry for the strange english, it's not my foreign language :)

Nice evening fellows

Eisenbahnplatte

1

There are 1 answers

1
iseletkov On

I have faced the same issue (or something very similiar).

Hibernate 5.2.17.Final + PostgreSQL + Inheritance.JOINED.

Solved it by removing "catalog" attribute from mapping. Try to replace

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

with

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

Hope this helps.