I have an Apache Tomcat + Hibernate based application. I have a class MyModel and a class MyViewModel which decorates an object of type MyModel.
When I get a request I return several instances of MyViewModel in the Map. Lets say an instance is x. When i try to access ${x.comments}, I get a property not found exception.
I have double checked that MyModel contains a getComments() and setComments() method.
Also MyViewModel contains getComments() method which invokes getComments() on the decorated object, returns empty string if null is returned.
Now the surprising part is that this code was working yesterday when I added the comments field everywhere in my code. My database still has the comments field. But somehow the bean is not being identified properly.
I have made some changes to the code and now I am using jquery-ui to get to the page but I don’t see how that should make a difference as I can access all other fields except the comments field.
The Hibernate logs show that the select query is not fetching the comments field.
I tried restarting the server, my Eclipse IDE nothing seems to work.
Can you please help me identify the problem?
Thanks in Advance!
Fixed it!
The class MyViewModel was missing a default constructor.
Why I could not catch it earlier?
I had an old set of jar files under WEB-INF/lib. However when I configured the project in Eclipse I downloaded newer versions of the jar files in a separate directory and added them to the build path but my WEB-INF/lib still contained old jar files. I was eventually planning to have the new versions but since things were working fine I didn’t bother.
Now somehow this was working yesterday but I might have done some sort of “cleanup” before committing. I must have removed the default constructor from MyViewModel. But I may not have restarted the server before testing it and hence it was working fine.
Ideally this should have been caught during deployment itself. But somehow the new version of the jars was not catching the error. When I switched to the jars in the WEB-INF/lib directory the server started throwing an exception during initialization saying that the default constructor is missing because of which the bean could not be initialized. This fixed the issue.
I tried to reproduce this situation. I removed the default constructor put the old .classpath file back in the project directory and it would not catch the error during deployment but it would fail at runtime. The reason was that a couple of dependencies in .classpath which were not required and could also not be satisfied. So Eclipse showed me a red exclamation mark (not the cross sign which usually indicates a build problem). I now understand that the exclamation mark meant there was a validation error on my project and the project was not rebuilding as the build path contained missing dependencies.
So I removed the missing dependencies from my build path and the red exclamation mark disappeared. Now the error was caught during deployment itself.
So much for not using Maven.