• 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Getting Hibernate Mapping Exception - SingleTableEntityPersister

 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I'm having problems starting Spring Boot project. I'm googling for the last day or so. But nothing I tried worked.

Here is what I did so far. I was using JDK 13 and after this SO post (which is the closest to the problem I am facing), I switched to JDK 1.8 (jdk1.8.0_261).
Again same problem. After that, I added dependency, that was mentioned in SO post:



Also tried with latest version. Both version were saying that something is wrong with JAXB Maven plugin (part of our project uses Soap WS) and that (un)marshaling is not working correctly. For which I know it is not possible, since this is already in production and working fine.
I also tried to start the project from other branches, again same issue. Other developers start project normally. I cannot figure out where to look for and why this exception is occurring. According to the docs, SingleTableEntityPersister implements the "table-per-class-hierarchy" or "roll-up" mapping strategy for an entity class
and its inheritance hierarchy. This is implemented as a single table holding all classes in the hierarchy with a discriminator column used to determine which concrete class is referenced. I don't know how this can help me.

I also read somewhere, related with line 63 (stack trace bellow), that all model entity classes must have the default constructor. Okay, I was able to start the project even though some entities didn't have default constructors, so I add them anyway, again same problem. I tried also deleting my local database and creating jsut empty schema,
so Hibernate can do the rest, again same issue.

I'll post the pom.xml and stack trace.

pom.xml



Stack trace:



I haven't got any remote idea what I could change on my Windows machine to cause this nightmare.
 
Saloon Keeper
Posts: 23692
161
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you define a no-argument constructor for your SingleTableEntityPersister entity class?

All JPA Entity classes must define a no-argument constructor and (usually) overide the hashCode() and equals() methods.
 
Mike Gosling
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, as I said, I did add them on all entity classes and still same exception. All classes are using Object's hash and equal at the moment. SingleTableEntityPersister is Hibernate's class (https://docs.jboss.org/hibernate/orm/3.2/api/org/hibernate/persister/entity/SingleTableEntityPersister.html). Did you meant to extend that class? But, I don't see the reason why should I do that.  
 
Tim Holloway
Saloon Keeper
Posts: 23692
161
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh yeah, that thing.

Someone who had the same problem has listed the following 3 likely causes for that error:

1.  Your Java POJO Mapping class may not have the empty/default constructor.
2.  Your Set/List or any collection class may not have the default constructor or overridden hashcode and equals method. That is, the same rules apply for any joined collections/parent-children.
3.  Set name you have given in the java class and mapping .hbm.xml file may be different.

Note that having an .hbm.xml file is not recommended these days, so the third problem shouldn't be a problem.

But you cannot use java.lang.Object's hashCode and equals methods.

In JPA, you might have multiple versions of the same database row in memory in different objects. Like if you fetch a row and make changes to it. The only way that JPA can distinguish between the "before" and "after" versions of that row - instead of confusing them with other rows in the database is to consider them as the same row (equals) by comparing ONLY the keys of that object. Since hashCode must track equals(), that means customizing hashCode to hash only on the key field(s) as well.
 
Mike Gosling
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. 2. and 3. are checked.

I don't know what is hbm.xml and I'm 100% I don't have one in the project.

In JPA, you might have multiple versions of the same database row in memory in different objects. Like if you fetch a row and make changes to it. The only way that JPA can distinguish between the "before" and "after" versions of that row - instead of confusing them with other rows in the database is to consider them as the same row (equals) by comparing ONLY the keys of that object. Since hashCode must track equals(), that means customizing hashCode to hash only on the key field(s) as well.



This is probably correct, but I don't think that is the reason why I'm getting error above. Project is two and a half year in production without hash and equals. I deleted locally database, and initialized empty schema, again - same error. In application properties I tried to connect to the database of our test server, like so:



Again same error. Before Labor Day I made PR, before actually submitting it through Bitbucket, I tested code locally, using Swagger, everything worked. What now bugs me is how it is possible that my mentor was able to deploy that jar on test server and that application NOW is working normally on test server? She is not getting the error I'm getting and we looked the above stack trace, and couldn't get nothing.

I also tried with another computer here in the company but same thing happens. Java 8, MySQL 8.0 database, nothing.

 
Tim Holloway
Saloon Keeper
Posts: 23692
161
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mike Gosling wrote:
This is probably correct, but I don't think that is the reason why I'm getting error above. Project is two and a half year in production without hash and equals.



Lots of things "work" - until they don't. Sometimes you can fail to follow protocol and be lucky - for a while.

.hbm.xml is an XML file(s) that do the entity mapping for legacy Hibernate. Java annotations have superseded the need for them. Be glad.

Far more valuable than your Maven POM would be your Spring Framework application context definitions where you define your beans and their relationships.

You're obviously connecting something incorrectly, since SingleTableEntityPersister is designed to be instantiated internally by Hibernate with constructor arguments supplied and it appears that Spring is trying to explicitly construct an instance of SingleTableEntityPersister without constructor arguments. Spring also constructs singleton instances by default, but as I read it, each Entity class managed by SingleTableEntityPersister should have its own matching instance of SingleTableEntityPersister.
 
Mike Gosling
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I forgot to mention that I created new Workspace for STS...

Senior developer started application (hitting database on test server) on my machine by doing:

1. In horizontal menu in STS Project -> Clean...
2. Right click on project -> Maven -> Update project...
3. From cmd move to target directory in project and type following  command: "C:\Program Files\Java\jdk1.8.0_261\bin\java" -jar ProjectName.jar

He managed to start the project from CMD.

After that in STS:

In horizontal menu Window -> Preferences -> Java -> Installed JREs:

Before he selected the path to java it was installed this other checkbox.

Later I also managed to start the project to hit local database

From now on, first from cmd start the app and if it works, that means that IDE is causing problems
Screenshot_1.png
[Thumbnail for Screenshot_1.png]
 
Tim Holloway
Saloon Keeper
Posts: 23692
161
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you define a JDK or JRE into an IDE, you have to point to the ENTIRE JDK/JRE, not just its "bin" directory.

That's also true for command-line scripts that employ a JAVA_HOME environment variable.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic