Monday, October 24, 2005

Christian Bauer blogged sometime before about a Generic Hibernate Dao pattern with JDK 5. This pattern has the advantage of simplifying the dao construction, It also allows for direct access to the underlying Hibernate session witch makes it possible to use the Hibernate powerfull API for data manipulation. The only issue I can think of, as a Spring Framework user, is intergation with Spring Framework declarative services, mainly transaction demarcation.

I updated Christian code to make the Generic Dao easily advisable by Spring Framework ProxyFactories to provide transactions management and other enterprise services.

/** Copyright 2002-2004 the original author or authors.** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at** http://www.apache.org/licenses/LICENSE-2.0 ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/

/** Copyright 2002-2004 the original author or authors.** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at** http://www.apache.org/licenses/LICENSE-2.0 ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/

Spring Framework HandlerExceptionResolver allows to build Exception Handlers that can be configured to trap exceptions and return a ModelAndView. They work in a simillar way to Struts ExceptionHandlers.

A Spring Framework/Hibernate user asked for a / magic / easy / way to convert Spring Framework thrown Exception into User Defined Exception without putting a try-catch block in all my methods.

I think we can achieve this using the magic of AOP. All we have to do is create an interceptor and hock it into the applicationContext.xml without having to change one line of code into our classes nor modify the bean configuration of DAOs / Services.

A Spring Framework/Hibernate user asked for a / magic / easy / way to convert Spring Framework thrown Exception into User Defined Exception without putting a try-catch block in all his methods.

I think we can achieve this using the magic of AOP. All we have to do is create an interceptor and hock it into the applicationContext.xml without having to change one line of code into our classes nor modify the bean configuration of DAOs / Services.