Joined subclass/superclass tables are not created while initializing because same table name exists in another DB.

Description

Our project has more than 50 tables and we use hibernate. In our setup we have a requirement to run 2 Applications in same server. When first application is already running in a machine and we try to run second application exception mentioned at the end is being thrown. After a bit of research, I understood that this is happening because JPA 2, and we need to mention schema attribute in hibernate configuration to avoid checking in public namespace. This is working fine as long as there is no joined subclasses defined in the configuration. For Joined subclasses and superclass its throwing mapping exception. Is there any configuration I am missing ?

Exception:
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.internal.SessionFactoryImpl.(SessionFactoryImpl.java:346) at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:708) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)

Caused by: org.hibernate.AssertionFailure: Table db.A not found at org.hibernate.persister.entity.AbstractEntityPersister.getTableId(AbstractEntityPersister.java:5107) at org.hibernate.persister.entity.JoinedSubclassEntityPersister.(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) ... 10 more

StackOverflow question I raised:
https://stackoverflow.com/questions/65609769/hibernate-joined-subclass-table-is-not-creating-when-same-table-name-exists-in-d

Environment

MySQL 8.0.17-commercial, Hibernate 5.0.7, Java 1.8.0_261

Activity

Show:
Babu Reddy
January 13, 2021, 6:38 AM

Referred this hibernate bug:

Andrea Boriero
January 13, 2021, 2:20 PM

Hi , I have tested it with 5.4 and I cannot reproduce the issue.

Remember that with MySQL it is necessary to use the catalog and not the schema attribute

Assignee

Unassigned

Reporter

Babu Reddy

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Critical
Configure