• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate referencing abstract entity for constraints

 
Ranch Hand
Posts: 66
MyEclipse IDE Firefox Browser Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I have the following error in my Hibernate log. I am using ONLY the JPA facilities of Hibernate to map my tables to MySQL. Now the above error makes since Subject is defined like the following-:




Its an abstract entity and not a mapped super class since I need to use it in queries.

Now I have a subclass of Subject called Theory which is a normal entity.

My question is that why is hibernate TRYING to add a constraint to an abstract entity ? Should'nt it be smart enough and the see the TABLE_PER_CLASS strategy placed there. Should'nt it only refer to the child classes ? If its abstract there is no way of an entity existing.

Is this a bug in the Hibernate code ?

Using version 5.0.0.CR4
 
Ranch Hand
Posts: 417
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I do not think it is a bug. Since you have no common table, you would need to define the constraint in every subclass table. I don't think constraints can be inherited.

Consider using InheritanceType.JOINED or even InheritanceType.SINGLE_TABLE if you want to declare the constraint only once for all your subclasses.

That is my understanding but I haven't investigated in depth.
 
Sreyan Chakravarty
Ranch Hand
Posts: 66
MyEclipse IDE Firefox Browser Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

A.J. Côté wrote:Hello,

I do not think it is a bug. Since you have no common table, you would need to define the constraint in every subclass table. I don't think constraints can be inherited.

Consider using InheritanceType.JOINED or even InheritanceType.SINGLE_TABLE if you want to declare the constraint only once for all your subclasses.

That is my understanding but I haven't investigated in depth.



Constraints are being inherited. My sub classes are being mapped with the correct constraint. I cannot use JOINED or SINGLE_TABLE because of my requirement and performance reasons.
 
A.J. Côté
Ranch Hand
Posts: 417
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Strange... How can you tell that your constraints are inherited if export schema fails?
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
IMO this is a bug in Hibernate 5.
I have the same issue in Hibernate 5.0.1. The same code with Hibernate 4.x works fine.
 
Sreyan Chakravarty
Ranch Hand
Posts: 66
MyEclipse IDE Firefox Browser Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kai Prünte wrote:IMO this is a bug in Hibernate 5.
I have the same issue in Hibernate 5.0.1. The same code with Hibernate 4.x works fine.



Are you sure it works fine in Hibernate 4 ?
 
Sreyan Chakravarty
Ranch Hand
Posts: 66
MyEclipse IDE Firefox Browser Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

A.J. Côté wrote:Strange... How can you tell that your constraints are inherited if export schema fails?



The schema export does not completely fail. Just for the table that I have given in my topic. All the other tables are exported properly.
 
Kai Prünte
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sreyan Chakravarty wrote:

Kai Prünte wrote:IMO this is a bug in Hibernate 5.
I have the same issue in Hibernate 5.0.1. The same code with Hibernate 4.x works fine.



Are you sure it works fine in Hibernate 4 ?



Yes!
 
A.J. Côté
Ranch Hand
Posts: 417
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sreyan Chakravarty wrote:

A.J. Côté wrote:Strange... How can you tell that your constraints are inherited if export schema fails?



The schema export does not completely fail. Just for the table that I have given in my topic. All the other tables are exported properly.



Strange, for me, schema export either succeeds or fails completely and no tables are created. Of course if your tables already exists in the db, hibernate won't touch them in case of failure.

 
Kai Prünte
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

A.J. Côté wrote:

Sreyan Chakravarty wrote:

A.J. Côté wrote:Strange... How can you tell that your constraints are inherited if export schema fails?



The schema export does not completely fail. Just for the table that I have given in my topic. All the other tables are exported properly.



Strange, for me, schema export either succeeds or fails completely and no tables are created. Of course if your tables already exists in the db, hibernate won't touch them in case of failure.



I am using Hibernate to create the DDL scripts, but Hibernate does not execute it. I decorate the generated statements and execute them by myself. However I can compare the generated scripts from Hibernate 4.3.11 and 5.0.1. Hibernate 4 neither create the "create table" nor the "alter table" statement. Hibernate 5 creates only the "alter table" statement.
 
reply
    Bookmark Topic Watch Topic
  • New Topic