PanacheEntity 中的@Transactional?

nim*_*o23 4 quarkus

这在 quarkus 中允许吗?

@Entity
public class User extends PanacheEntity  {

    // is @Transactional annotation allowed within an Entity
    @Transactional 
    public static final updateName(String name){
       ...
    }

}
Run Code Online (Sandbox Code Playgroud)

quarkus 是否允许在静态方法@Transactional中设置注释(通常不绑定到上下文(CDI-Bean))..取决于.PanacheEntity

ale*_*der 5

不,这是不允许的。

你会得到javax.persistence.TransactionRequiredException: Transaction is not active, consider adding @Transactional to your method to automatically activate one.

您必须将注释添加@Transactional到资源的包装方法中。

内置方法persist()没有设置注释,因此即使是 quarkus 默认方法也无法在没有包装的@Transactional.