01: /*
02: * Copyright 2005 Joe Walker
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.directwebremoting.hibernate;
17:
18: import java.beans.PropertyDescriptor;
19:
20: import net.sf.hibernate.LazyInitializationException;
21:
22: import org.directwebremoting.extend.MarshallException;
23: import org.directwebremoting.extend.Property;
24: import org.directwebremoting.impl.PropertyDescriptorProperty;
25:
26: /**
27: * A {@link Property} that catches hiberntate exceptions.
28: * This is useful for Hibernate 2 where lazy loading results in an exception
29: * and you are unable to detect and prevent this.
30: * @author Joe Walker [joe at getahead dot ltd dot uk]
31: */
32: public class H2PropertyDescriptorProperty extends
33: PropertyDescriptorProperty {
34: /**
35: * Simple constructor
36: * @param descriptor The PropertyDescriptor that we are proxying to
37: */
38: public H2PropertyDescriptorProperty(PropertyDescriptor descriptor) {
39: super (descriptor);
40: }
41:
42: /* (non-Javadoc)
43: * @see org.directwebremoting.impl.PropertyDescriptorProperty#getValue(java.lang.Object)
44: */
45: @Override
46: public Object getValue(Object bean) throws MarshallException {
47: try {
48: return super .getValue(bean);
49: } catch (LazyInitializationException ex) {
50: return null;
51: } catch (Exception ex) {
52: throw new MarshallException(bean.getClass(), ex);
53: }
54: }
55: }
|