Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
hibernate延迟加载后的Spring执行方法_Spring_Hibernate_Lazy Loading_Spring Data Jpa_Spring Aop - Fatal编程技术网

hibernate延迟加载后的Spring执行方法

hibernate延迟加载后的Spring执行方法,spring,hibernate,lazy-loading,spring-data-jpa,spring-aop,Spring,Hibernate,Lazy Loading,Spring Data Jpa,Spring Aop,我使用的是Spring Boot 1.3.1,包括Spring数据JPA。我想在任何延迟加载之后执行一个方法,对加载的对象进行一些转换 例如: @Entity @Table(name = "commune") public class Commune extends CommuneBase { } @MappedSuperclass public abstract class CommuneBase { private Region region; } @Entity @Table(

我使用的是Spring Boot 1.3.1,包括Spring数据JPA。我想在任何延迟加载之后执行一个方法,对加载的对象进行一些转换

例如:

@Entity
@Table(name = "commune")
public class Commune extends CommuneBase {
}

@MappedSuperclass
public abstract class CommuneBase {
    private Region region;
}

@Entity
@Table(name = "region")
public class Region extends RegionBase {
}

@MappedSuperclass
public abstract class RegionBase {
    private String name;
}
测试代码:

Commune commune = communeRepository.findOne(communeId);
Region region = commune.getRegion();
现在应该翻译
getRegion()
的结果。 我尝试了一个方面和以下切入点:

@AfterReturning(pointcut="execution(* com.mycompany.application.data.domain.Commune.getRegion(..))", returning="returnValue")
切入点不被调用。同一项目中的其他切入点正在按预期工作


非常感谢Spring提供的任何帮助

Spring只会将AOP应用于它知道的bean和控制器。您试图在实体上使用Spring AOP,但这是行不通的。有时。。。谢谢你的提示!有没有办法在没有AOP的情况下解决这个问题?你想实现的是什么?你认为你需要使用AOP来解决它。我的应用程序是多语言的,我希望在任何时候根据登录用户获得某个区域的实例时,都能获得该区域的正确翻译。因此,对于通过
regionRepository
直接加载,我通过切入点实现了它。因此,我也尝试了延迟加载的实例。我不想在代码中的任何时候调用一个
translate(Region)
,因为您的做法是错误的。Spring支持I18N,您应该与之集成,而不是尝试使用AOP来开发解决方案。