| Sleepless in Chicago |
|
|
|
| Written by Chintan Rajyaguru | |||||||||
| Friday, 15 December 2006 18:07 | |||||||||
|
This blog entry is a rant - a big one against spring, hibernate combo. If you run a database query and do not get any results back, here is what you would typically do:
However, if you are using spring - hibernate combo, let me give you one more Check that all hibernate mapping files are added to the list of mapping files in the mappingResources property of LocalSessionFactoryBean provided by spring. I didn't, and it cost me a long day and night figuring it out. But that's no ranting, that's lesson learned. The ranting comes from the fact that neither spring nor hibernate cared to tell me about a missing mapping file. If my DetachedCriteria is defined for MyDomain, I would expect hibernate to lookup its mapping file and tell me if it can't find the file. Instead, hibernate ran the query happily and returned zero results! No errors, no exceptions, no warning - not even a tiny debug statement. In fact, the behavior of the framework was misleading. Usually, when you set show_sql to true, hibernate prints all the sql queries it generates. In this case, it didn't print the query leading me to believe it couldn't generate the query. I first blamed it on my usage of projections, then on result set transformer, then on hibernate filters, then on the version of business objects jar file I was using, then on WebSphere, then on database, then on hibernate caching and the list goes on... For every possibility, I ended up changing code/configuration, adding more log statements, redeploying the application and testing. I even ran another transaction that used the same DAO method and made sure that query was printing in the log and executing correctly. Many will put the blame on me and they are right if they do. If the framework says you have to specify mapping files, you have to or face consequences, but I was just hoping to see the consequences in my log files. The story doesn't end here. After I finally added the mapping file entry and ran again, I got an error similar to "no class MySubDomain found." This is valid because MyDomain would return results as MySubDomain based on a column selector BUT I think the error is misleading. In a different situation, the developer would think the class was not packaged in the domain objects jar file. In my case however, since I knew my earlier problem was a missing mapping file, it immediately occurred to me that the mapping file for MySubDomain was probably missing. After adding both mapping files, hibernate executed the query (like it did before) but this time it also returned results (thank you!). This incident has created yet another dent in my love for spring - hibernate as enterprise frameworks (yes, there are some dents already but let's talk about them later!). As of now, I don't know whether spring or hibernate caused this. I will try to find out when I am done with other more important things I have to do. In the mean time, my ranting continues...
Powered by !JoomlaComment 3.26
3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."
|
|||||||||
| Last Updated on Friday, 15 December 2006 18:12 |



