Click image
to access
book information
Web Development with Java
Using Hibernate, JSPs and Servlets
Downey, Tim
ISBN: 978-1-84628-862-3
Book Web Site

Controller Errors

Many times when develping a servlet there will be a 500 error generated by the server. Usually, there will also be a stack trace displayed. However, many times the lines that you need to see in the stack trace are not displayed in the browser, but are only visible in the Tomcat error log file.

To see these errors on the ocelot host,

  1. Look in the your log folder. For my course, this is located in webapps/WEB-INF logs folder
  2. Open the most recent error log
  3. Scroll to the bottom and read the most recent stack trace.
  4. Look for the statements that give information about the error, there are usually several of them.

Error: Cannot open connection
org.hibernate.exception.GenericJDBCException: Cannot open connection
   org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:91)
   org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:79)
Solution: Check the mysql connection parameters
Log into mysql directly on ocelot
mysql -u your-username -p
Enter your password: your-password

mysql> use your-database

and be sure that you are using the correct username, password and database name in your controller.
  props.setProperty("hibernate.connection.url", 
                    "jdbc:mysql://ocelot.aul.fiu.edu:3306/your-database");
  props.setProperty("hibernate.connection.username", "your-username");
  props.setProperty("hibernate.connection.password", "your-password");

Error: Could Not Insert
org.hibernate.exception.SQLGrammarException: could not insert: [hw4.Controller3.RequestData]
	org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:65)
	org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
	org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:1985)
	org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2404)
Solution: Usually this means that you must create the database tables.
In the web.xml file, set the create parameter for the controller to true to create the tables in the database. After the tables are created, set it back to false so that data will not be destroyed when the web application is restarted.

If you have already done this and are still getting this error then keep reading...

Additional Information in Tomcat error log: SQL Syntax Error
Open the Tomcat error log and look for additional information.
Caused by: java.sql.SQLException: You have an error in your SQL syntax near 'order, food, side) values ('asd1234', 'asdf', null)' at line 1
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2851)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1531)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1622)
Solution: Illegal property name in the bean
This usually means that you have used a property name in your bean that is also a reserved word for SQL. In this example it is 'order'. This is a word that has special meaning to SQL, so it cannot be used as a column name in a table, and therefore, cannot be used as a property in a bean.

Rename the offending property. The offending property will be the first one listed in the SQL syntax error message.


Error: Could not get property value
java.lang.IllegalStateException: Could not get property value
  org.hibernate.validator.ClassValidator.getMemberValue(ClassValidator.java:272)
  org.hibernate.validator.ClassValidator.getInvalidValues(ClassValidator.java:212)
  org.hibernate.validator.ClassValidator.getInvalidValues(ClassValidator.java:183)
Additional Information in Tomcat error log: Wrong number of arguments
Caused by: java.lang.IllegalArgumentException: wrong number of arguments
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
Solution: You have placed a validation annotation on a setter.
Move the annotation to the getter. All validation annotations belong on the getters.
Error: Unable to find a value
javax.servlet.ServletException: Unable to find a value for "hobb" in object of class "hw4.RequestData" using operator "."
  org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:867)
  org.apache.jasper.runtime.PageContextImpl.access$1100(PageContextImpl.java:109)
  org.apache.jasper.runtime.PageContextImpl$12.run(PageContextImpl.java:787)
Solution: Property does not exist in the bean.
You have requested a property in a JSP, but that property does not have a getter in the bean.
Error: Servlet Exception with a Root Cause of Exception in Initialization
javax.servlet.ServletException
  org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:324)
  org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:200)
  org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:153)

root cause

java.lang.ExceptionInInitializerError
  utilities.HibernateUtil.initSessionFactory(HibernateUtil.java:67)
  hw5.Controller.initSessionFactory(Controller.java:41)
  hw5.Controller.init(Controller.java:36)
Additional Information in Tomcat error log: Could not determine type
Caused by: org.hibernate.MappingException: Could not determine type for: java.util.Map, for columns: [org.hibernate.mapping.Column(checked)]
        at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:266)
        at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253)
        at org.hibernate.mapping.Property.isValid(Property.java:184)
Solution: Recreate the tables
This error usually means that you have added a getter to the bean, but did not add a setter. You must either add the setter or mark the getter with the @Transient.

Create the setter or mark the getter method with the @Transient annotation.

Additional Information in Tomcat error log: No identifier specified for entity
Caused by: org.hibernate.AnnotationException: No identifier specified for entity: ch4.persistentData.RequestDataPersistent
  at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:645)
  at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:256)
  at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:191)
  at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1138)
  at utilities.HibernateUtil.initSessionFactory(HibernateUtil.java:65)
Solution: Missing or misplaced @Id annotation
During initialization, Hibernate needs to know the unique identifier field for all classes that are marked with the @Entity annotation. Be sure that there is a getter that returns a unique value and is marked with the @Id annotation.

Additional Information in the Tomcat error log: Annotated class should have a @javax.persistence.Entity
Caused by: org.hibernate.AnnotationException: Annotated class should have a @javax.persistence.Entity, @javax.persistence.Embeddable or @javax.persistence.EmbeddedSuperclass annotation: hw3.RequestDataExtended
        at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:334)
        at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:256)
        at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:191)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1138)
        at utilities.HibernateUtil.initSessionFactory(HibernateUtil.java:51)
Solution: Add the @Entity annotation to your bean.
All beans that are to have a table created for them in the database must have the @Entity annotation before the definition of the class.
  @Entity
  public class MyBean {
  ...

Error: Bean is not mapped
org.hibernate.hql.ast.QuerySyntaxException: RequestDataPersistent is not mapped. [from RequestDataPersistent]
	org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:145)
	org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:86)
	org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:70)
	org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:262)
	org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3041)
	org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2930)
	org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:688)
	org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:544)
	org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
	org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
	org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:216)
	org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:156)
	org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:103)
	org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:473)
	org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1060)
	org.hibernate.impl.SessionImpl.list(SessionImpl.java:1010)
	org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
	ch4.ControllerFull.getListData(ControllerFull.java:92)
Solution: Be sure that correct bean name is used everywhere.
If you look in the stack trace you will see the last reference in your code. If you look at this line in your code, you will see a reference to a bean that is not the bean for this application.

Be sure that all references to a bean are for your bean.


Error: Could Not Serialize
org.hibernate.type.SerializationException: could not deserialize
	org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:211)
	org.hibernate.util.SerializationHelper.deserialize(SerializationHelper.java:234)
	org.hibernate.type.SerializableType.fromBytes(SerializableType.java:78)
Solution: Annotate array properties in bean.
Be sure that the getter for any array properties are marked with the OneToMany and IndexColumn attributes.
Error: Batch Update
org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
	org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:65)
	org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
	org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:200)
Additional Information in the Tomcat Error Logs:
Caused by: java.sql.BatchUpdateException: Table 'databaseName.RequestDataPersistent_wclass' doesn't exist
        at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1629)
        at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPreparedStatement.java:1723)
Solution: Recreate the tables
This usually happens when you have added properties to your bean, but have not added these new columns to the database. Change the create parameter in the web.xml file to true and restart the web app. Remember to change this parameter back to false after the tables have been created.
Error: Could not instantiate ClassValidator
java.lang.IllegalArgumentException: could not instantiate ClassValidator at org.hibernate.validator.ClassValidator.createValidator(ClassValidator.java:287) at org.hibernate.validator.ClassValidator.createMemberValidator(ClassValidator.java:255) at org.hibernate.validator.ClassValidator.initValidator(ClassValidator.java:208)
Additional Information in the Tomcat Error Logs:
Caused by: java.util.MissingResourceException: Can't find resource in validator bundles, key validator.notEmpty at org.hibernate.validator.interpolator.DefaultMessageInterpolator.replace(DefaultMessageInterpolator.java:107) at org.hibernate.validator.interpolator.DefaultMessageInterpolator.initialize(DefaultMessageInterpolator.java:66) at org.hibernate.validator.interpolator.DefaultMessageInterpolatorAggerator.addInterpolator(DefaultMessageInterpolatorAggerator.java:37)
Solution: Old JAR Versions
The versions of the JAR files for hibernate are out of date. The problem JAR files are most likely hibernate3.jar and hibernate-annotations.jar. Be sure that all the JAR files are up to date.