Common Problems
Q: The compiler complains about the import for javax.persistence.GeneratorType not being resolved.
Q: How do I get rich text editing to work?
Q: I'm getting a LazyInitializationException in my equals method.
----
Q: I get the following error: org.hibernate.MappingException: Could not determine type for: java.util.Set, for columns: [org.hibernate.mapping.Column(dataItems)]
A: To avoid this Hibernate error you need to specify the content of the Set like this:
public Set<DataItem> getDataItems() { return objectmembers; }
and DataItem (or whatever) must be in the hibernate.cfg.xml also.
Q: When I try to build my project I get an error from ant: Compiler Adapter 'org.apache.tools.ant.taskdefs.compilers.AptExternalCompilerAdapter' can't be found.
A: Trails makes use of apt ant task that is not currently in the released version of ant. In order to function properly, an apt-ant.jar must be copied into the ant.home/lib directory. The Trails build.xml should do this automatically, but may have problems if your ant.home variable is not set for some reason. Also, if you are running from Eclipse you will need to make sure you have ant-apt.jar in the Ant Home Entries section of the Ant Runtime configuration.
Q: I upgraded trails in my trails project with the latest current trails version in CVS. After upgrading my project I am getting a RuntimeException: bad WeaverState.Kind: 67.
A: This may be caused by the fact that the upgrade-project or create-project task does not create a new trails.jar and trails-aspect.jar in the deploy directory if it already existed. So you can fix this by running ant clean jar from within the trails project directory (not your own trails project) and manually copy the trails.jar and trails-aspect.jar to your own trails project lib directory.
On this link you can find some more information about the bad WeaverState itself: http://www.nabble.com/Compilation-problems-in-AJDT-code-t529740.html
Q: I'm getting: "/build.xml:144: fail due to BCException 'malformed org.aspectj.weaver.Declare attribute java.io.EOFException' 'ABORT' (1 exceptions)" when I'm trying to build from source.
A: Generally it means you have compiled classes with one version of AspectJ and you are trying to do an incremental build with a different version. Have you tried doing a clean first? ![]()
Q: How do I get rich text editing to work?
A: First, rich text editing is a feature that does not exist in a released version. The fckeditor is included in version 0.8, but it is not activated. Second, you must ensure that your property has @PropertyDescriptor(richText=true).
Q: When I store a double value, say 12.2, it gets stored correcly as double precision value in the database and it gets displayed as 12.2. But when I edit the record again, it get's displayed as 12 and stored as 12.0.
A: You need to specify @PropertyDescriptor(format = "0.000") for the property.
Q: I'm getting a LazyInitializationException in my equals method.
A: If you are using EqualsBuilder to implement equals you may run in to problems when the object has dependent objects. This is because EqualsBuilder tries to compare all fields using reflection. This causes all lazy collections of dependent objects to be loaded - probably not what you want.
There are two ways of fixing the problem: You can use an instance of EqualsBuilder and only compare the local fields; or you can make sure that there is a surrounding Hibernate session. The first method is probably the simplest and best as long as your objects have enough local information to distinguish instances.
For the second method, Gert Jan Verhoog suggests the following:
First, I used Spring's OpenSessionInViewFilter to open a session per request. I created a subclass of this filter that sets the session's flushmode to AUTO instead of NEVER to prevent "the session is read-only" errors.
Then, I removed the transaction proxies around the persistenceService bean, because we found that the transaction manager closed the session prematurely. I would like to have transaction proxies in place, though, but I haven't been able to get this to work yet.
With this setup, it's possible to access associations, collections and other objects in a larger object graph, as long as it's all within the same session. Basically this is everything from the moment a user clicks on a link until the result of that user action is displayed in the browser window.
Furthermore, I tweaked the hibernate.max_fetch_depth property. Setting this to 0 disables association fetching altogether. If you set this to a value larger than 0, and you specify a fetch="join" attribute in your many-to-one hibernate mappings, it's possible to pull a larger object graph from the database in a single hibernate operation. This way you can access the associated objects even when the owning session was closed.
It's also possible to have the error if the object is not in the current Hibernate session — for example if it came from the HTTP session. In this case you just have to reattach the object to the Hibernate session:
public void reattach(Object o) { try { persistenceService.reattach(o); } catch (Exception e) { log.error("Could not reattach object to Hibernate session: " + o, e); } }
Q: When I try to deploy, I get the error: Compiler Adapter 'org.apache.tools.ant.taskdefs.compilers.AptExternalCompilerAdapter' can't be found.
A: This usually means that the install-apt task failed for some reason to copy ant-apt.jar into your ant.home/lib directory. Make sure that your $ANT_HOME environment variable is set correctly and try to run the install-apt task again. You can also manually copy it there and you should be fine.
Q: When the application starts, I get an error like: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'descriptorService' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.IndexOutOfBoundsException: Index: 4, Size: 4
A: This is probably a problem with a @PropertyDescriptor annotation. When you use indexes, you have to make sure that you have that many items, otherwise things will blow up.
Q: I'm getting an error message like: Failure invoking listener method 'public void org.trails.page.EditPage.saveAndReturn(org.apache.tapestry.IRequestCycle)' on $EditPage_36@cbb612[DefaultEdit]: target is null for method add
A: The collection probably isn't initialized to an empty instance. Make sure you do something like:
Set<ChildObject> children = new HashSet<ChildObject>();
Q: The compiler complains about the import for javax.persistence.GeneratorType not being resolved.
A: The Hibernate annotations have been updated to 3.1beta8 in TRAILS v0.9. There is a change to the annotations for generated ids. Existing code will need to change to use the newer annotations.
You will need to replace the "@Id(generate = GeneratorType.AUTO)" annotation with "@Id @GeneratedValue(strategy=GenerationType.AUTO)"
