001/* 002 * Copyright 2002-2012 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.orm.hibernate3.support; 018 019import org.hibernate.EmptyInterceptor; 020 021import org.springframework.aop.scope.ScopedObject; 022import org.springframework.aop.support.AopUtils; 023 024/** 025 * Hibernate3 interceptor used for getting the proper entity name for scoped 026 * beans. As scoped bean classes are proxies generated at runtime, they are 027 * unrecognized by the persisting framework. Using this interceptor, the 028 * original scoped bean class is retrieved end exposed to Hibernate for 029 * persisting. 030 * 031 * <p>Usage example: 032 * 033 * <pre class="code"> 034 * <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> 035 * ... 036 * <property name="entityInterceptor"> 037 * <bean class="org.springframework.orm.hibernate3.support.ScopedBeanInterceptor"/> 038 * </property> 039 * </bean></pre> 040 * 041 * @author Costin Leau 042 * @author Juergen Hoeller 043 * @since 2.0 044 * @deprecated as of Spring 4.3, in favor of Hibernate 4.x/5.x 045 */ 046@Deprecated 047@SuppressWarnings("serial") 048public class ScopedBeanInterceptor extends EmptyInterceptor { 049 050 @Override 051 public String getEntityName(Object entity) { 052 if (entity instanceof ScopedObject) { 053 // Determine underlying object's type. 054 Object targetObject = ((ScopedObject) entity).getTargetObject(); 055 return AopUtils.getTargetClass(targetObject).getName(); 056 } 057 058 // Any other object: delegate to the default implementation. 059 return super.getEntityName(entity); 060 } 061 062}