Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.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
Java 如果使用spring AuthenticationProcessingFilter扩展类,则无法在jpa中持久化实体_Java_Spring_Jpa - Fatal编程技术网

Java 如果使用spring AuthenticationProcessingFilter扩展类,则无法在jpa中持久化实体

Java 如果使用spring AuthenticationProcessingFilter扩展类,则无法在jpa中持久化实体,java,spring,jpa,Java,Spring,Jpa,我有这样的类层次结构 public class AccessHistoryJpaDAO extends PaginatedJpaDAO<AccessHistory, Long> implements AccessHistoryDAO 然后我扩展了spring的AuthenticationProcessingFilter 公共类CustomAuthenticationFilter扩展了AuthenticationProcessingFilter 和重写方法 @Override pub

我有这样的类层次结构

public class AccessHistoryJpaDAO extends PaginatedJpaDAO<AccessHistory, Long>
implements AccessHistoryDAO
然后我扩展了spring的AuthenticationProcessingFilter

公共类CustomAuthenticationFilter扩展了AuthenticationProcessingFilter

和重写方法

@Override
public Authentication attemptAuthentication(HttpServletRequest request)
        throws AuthenticationException
在这个方法中,当我调用

getAccessHistoryDAO().logIn(entity);
hibernate无法持久化实体,但 当我打电话给direclty

getAccessHistoryDAO().save(entity)

上面的方法是一个持久的实体,我试图找出它,但没有任何线索,任何帮助都将不胜感激。谢谢。

代理AOP似乎存在一个众所周知的问题

我猜在save方法中有一个@Transactional注释。但是,只有从其他Springbean调用该方法时,才会考虑此注释。如果从相同的Springbean this.save调用它,则不会调用AOP代理,因此不会启动事务

您至少可以用三种不同的方式处理此问题:

在登录方法处添加@Transactional注释,或 使用显式事务管理而不是声明式事务管理, 使用RealAspectJ而不是Spring代理AOP这就是我要做的
我忘记的一件事是,hibernate并没有异常或奇怪的行为,它是一个返回实体,id表示插入成功,但表中并没有行。但我一调用getAccessHistoryDAO.saveentity,表中就有一行。它会抛出任何异常还是不会持久化实体?在Ralph提到的这种情况下,不会有例外,但hibernate不会启动事务,因此不会在数据库中插入任何记录感谢您的回复事实上您是对的我错过了@Transactional
getAccessHistoryDAO().save(entity)