Jan 20

At work we had a problem with randomly getting the org.hibernate.AssertionFailure: collection was not processed by flush exception thrown in various places.  After searching for a solution we finally found a blog that mentioned a similar issue and a working solution.

Our base model class had an overridden equals() method and hashCode() method that was causing the problem.  If you have overridden a method used for comparison in collections, such as equals(), hashCode(), compare(), be wary that your method is not causing hibernate to instantiate lazily loaded objects during flush.  We had a complex equals() method that used reflection to compare values within a model.  This is bad practice and the equals method should be overridden to check attributes that form a natural key for the object.  For performance as well as resolving this problem we changed our equals method to do the following:

  1. Check if the objects were the same: obj == otherObj
  2. Check if the objects’ surrogate keys were equal: obj.getId() == otherObj.getId() — or obj.getId().equals(otherObj.getId()), depending on your Id datatype
  3. Check if the objects’ natural/business keys were equal: obj.getSSN().equals(otherObj.getSSN())
Those are just examples and show how we fixed the issue.  The main point is that you should reevaluate your equals, hashCode, and comparator methods to determine if that is causing the flush problem.  Hibernate actually has reasoning and best practices for overriding them that you can follow here.

Credit on my team goes to Reddy Kasireddy, and to the blog where he found it:
http://www.jroller.com/jshingler/entry/org_hibernate_assertionfailure_collection_was

Dec 29

Long story short, if you see:
org.hibernate.console.HibernateConsoleRuntimeException: Could not create JPA basedConfiguration, you may have your workspace and/or project in a path with a space in one of the directory names.

Let me expound:
I recently downloaded the newest JBoss Developer Studio (JDS) and thought “hey I’ll whip up a JBoss Seam application using EJB3.0, JPA, and Hibernate.” I watched a tutorial and saw how awesome their Hibernate Configuration capabilities were. Then I tried to replicate it. I use the wizard to create a new Seam Web Project and boom, the very next step I get an error.

The full error was:
org.hibernate.console.HibernateConsoleRuntimeException: Could not create JPA based Configuration
Could not create JPA based Configuration
<No message>
java.lang.reflect.InvocationTargetException
java.lang.reflect.InvocationTargetException: <no message>
java.lang.reflect.InvocationTargetException
javax.persistence.PersistenceException: java.lang.IllegalArgumentException: Unable to visit JAR file:/C:/Documents and Settings/jmarcum/jbworkspace/example/build/classes. Cause: Illegal character in path at index 18: file:/C:/Documents and Settings/jmarcum/jbworkspace/example/build/classes
java.lang.IllegalArgumentException: Unable to visit JAR file:/C:/Documents and Settings/jmarcum/jbworkspace/example/build/classes. Cause: Illegal character in path at index 18: file:/C:/Documents and Settings/jmarcum/jbworkspace/example/build/classes
java.lang.IllegalArgumentException: Unable to visit JAR file:/C:/Documents and Settings/jmarcum/jbworkspace/example/build/classes. Cause: Illegal character in path at index 18: file:/C:/Documents and Settings/jmarcum/jbworkspace/example/build/classes
Unable to visit JAR file:/C:/Documents and Settings/jmarcum/jbworkspace/example/build/classes. Cause: Illegal character in path at index 18: file:/C:/Documents and Settings/jmarcum/jbworkspace/example/build/classes

Now the “Could not create JPA based Configuration” could be for several reasons, but one that you won’t find anywhere on the internet (except right here, and I know this because I looked) is because of your file location. You can’t have any spaces in the path to your filename. Like by default, JDS will put your stuff in C:\Documents and Settings\yourname\workspace. First off, thanks Windows for putting spaces in my default directories, that helps with everything. Second, thanks JDS for giving me the worst error message ever. Now true, they gave me a hint in the ‘details’, but the main error that shows up is much less helpful.

So anyway, hope that helps some other poor soul doomed to develop on Windows. Word to the wise, if you are on windows and developing using Java, always put your source in a short path (name-wise) that has no spaces. Like c:\source. Same thing for your maven repository. Get that shiz out of your home directory and move it to c:\repo. You can specify where the repository is in your settings.xml in your home directory. This will help in lots of things, like tools that don’t expect spaces, and limitations with windows command length (like if you have a super long classpath).

Cheers.

Sep 16

Ever seen this error:
com.google.gwt.user.client.rpc.SerializationException: Type ‘your.class.Type’ was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.

Or this error:
Error: Type ‘your.class.Type’ was not serializable and has no concrete serializable subtypes

It can be caused by multiple reasons, but if you feel like you have done everything correctly (included source in GWT’s classpath during compilation, implement Serializable, google searched, prayed to the god of your choice) then you probably have the problem I had.  your.class.Type doesn’t have a default constructor.

So if your class has no default constructor (one that takes no arguments), add it and try again.  If that doesn’t fix it, and you find out what else is wrong, please post it as a comment here.

Also as an added bonus tip, when google searching for errors, your error usually is of the pattern: “something common to all errors of this type” “something specific to my project” “some more common stuff”.  Like in this error you have common stuff:
com.google.gwt.user.client.rpc.SerializationException: Type

Then specific stuff: 
‘your.class.Type’

Then more common stuff:
was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.

The way to search for that is take your stuff and replace it with an asterisk (*) and put the whole thing in quotes and google will wildcard your specific stuff and you will get better results.  So a good way to search for this error would be (trimming because google only lets you search 32 words):
com.google.gwt.user.client.rpc.SerializationException: Type * was not included in the set of types which can be serialized by this SerializationPolicy”

Hope either of those things help someone.