Archive for the ‘hibernate’ tag
Hibernate MappingException: persistent class not known
“Caused by: org.hibernate.MappingException: persistent class not known: …“
The root of this exception is, that the entity hibernate is trying to load, is either not configured at all or not configured correctly. Check the following, if you encounter this exception:
- The entity is mapped correctly in the hibernate.cfg.xml.
- If annotations are being used, the entity in question is annotated and annotated correctly as pointed out here.
If you see: “Caused by: org.hibernate.MappingException: Association references unmapped class XYZ…”, make sure, that the class XYZ is configured correctly and check the steps above.
MySQL Communications Link Failure
Recently we were baffled by the “Communications Link Failure” issue on our servers.
Our setup:
Jahia 6 on Tomcat (Apache DBCP, Spring, Hibernate, MySql).
Here’s what we observed:
1. The exception is generally caused by a connection that has become stale. The connections in the pool become stale after the wait_timeout period set in the my.cnf on the mysql server. The pool implementation should somehow validate connections before using them (which is what validationQuery is for). However, setting validationQuery has performance side effects.
2. Setting the autoReconnect (jdbc:mysql://DBHOST/schema?autoReconnect=true) to true on the driver should try to reconnect in case the connection has become stale each time a connection is made. However, this has no effect anymore and can be removed.
After trying a few other options, what helped us was setting the “wait_timeout” value in the my.cnf to a high value. (Some value greater than the max amount of inactivity in the system).
If the wait_timeout is set to a high value so that during the period of inactivity the connections do not become stale, this exception will not be raised.
Of course, the other option is to handle stale connections in your code and recover from such exceptions or use a connection pool implementation that does this for you.