- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想知道是否有一种方法可以重写某些 JpaRepository 的删除方法,而不必重写其余方法。
目前我有类似的东西
public interface UserRepo extends JpaRepository<User, Long>
{
findUserById(long id);
findUserByEmail(String email);
// etc...
}
我想重写 CrudRepository
中的 delete(T Entity)
方法。为此,我尝试实现 UserRepo
但随后我必须实现所有 findByX
并且还没有真正找到有关如何正确执行此操作的任何信息。
是否有任何注释可以添加到实体类中的函数,以便它在调用UserRepo.delete(myUser)
时运行?
提前致谢!
最佳答案
不确定我对你的理解是否足够清楚,但让我们尝试一下:
... I have to implement all the findByX ...
你不这样做,如果你在接口(interface)中使用合适的对流命名方法,spring将生成JPQL片段,请查看this和 this文章
... Is there any annotation to add to a function in the Entity class so it runs when you call UserRepo.delete(myUser)? ...
您可以在实体类中的方法上使用@PreRemove
/@PostRemove
注释:
@PreRemove / @PostRemove
public void someMethod() { ... }
关于spring - JpaRepository中的自定义删除方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53206163/
我的 spring 应用程序中有一个功能有问题。我在同一个数据库中有 2 个表,都包含相同类型的数据(ID、标题、描述和日期)。我可以从一张表中获取数据,但不知道如何插入到第二张表中。 在我的@Ser
我有如下 3 个实体类(示例取自 https://hellokoding.com/jpa-many-to-many-extra-columns-relationship-mapping-example
是否可以在没有实体的情况下使用 JpaRepository?在这种情况下,将其替换为 DTO。 如下示例 @Repository public interface BffRepository ext
我有使用 JPA 工具生成的用户实体和角色实体。 User 和 Role 是多对多的关系。我使用以下代码插入管理员,但是,没有数据插入到 user_role 表中。我还注意到角色类有 @JoinTab
我使用 JpaRepository 来保存数据,但 hibernate.show_sql 显示“选择”并且不会保存数据。以下是我的服务: @Autowired private UserReposito
我正在使用 Spring Boot、Hibernate 和 JPA 存储库来搜索数据。 我想通过登录用户的上下文来过滤搜索结果。例如。查找返回登录用户拥有的所有实体的方法?我有许多用于过滤的 JPA
如何从父进程中检索子进程? 假设我有父类和子类。我想从父方检索子项列表。 这是我的家长类。 +import ... @Entity public class Parent { @Id
我正在努力尝试创建一种方法来从数据库获取对象并加载依赖项。 在正常情况下,我永远不想加载它,所以我的两个对象看起来像这样: public class Training implements Seria
由于某些奇怪的原因,Jpa 生成的查询没有按预期生成。我使用 jpa 在我的存储库中编写了以下查询: 我的对象 @Id @GeneratedValue(strategy = Generatio
我正在尝试 Autowiring 服务中的存储库,但我不断收到以下错误 org.springframework.beans.factory.UnsatisfiedDependencyException
我是使用 JPA 的新手,我正在在线阅读教程,所有这些教程都从 JPARespository 扩展而来,如下所示 从此页面 https://www.callicoder.com/spring-boot
我正在制作一个应用程序,该应用程序保存用户配置文件和具有许多交易的钱包。 这是事务类: @Entity @Table(name = "transactions") public class Trans
我正在 IntelliJ 中使用 Spring Boot 我已经扩展了 JpaRepository 接口(interface),并创建了一个未在存储库变量中显示的查询到我的 Controller 中(
我只想返回特定的文件以进行服务。所以我在 JPARepository 界面中编写了以下代码: @Query(value="select r.id from Ride r") public List f
我正在使用 spring JpaRepository,并且希望使用 el 表达式提供具有通用派生 SQL 查询的通用接口(interface),如下所示: public interface BaseR
我正在尝试做一个非常简单的删除操作,但不知何故它不起作用,因为我将 DAO 更新为 JpaRepository。基本上是这样的: A a = aRepository.findOne(id); a.se
我像这样使用数据存储库: interface HerbadgeRepository extends JpaRepository { } 在甲骨文they say : To implement gene
我使用 Spring 与 Hibernate 和 JpaRepository 作为数据库存储库。 我有两个用于用户存储的类: @Entity public class User { @Id
我想要保护 JpaRepository,它将我的 OAuth 用户引用到授权角色 ROLE_ADMIN。现在我想知道我需要注释哪些方法。因此,当我想保护整个用户存储库时,登录不再起作用,因为它调用 f
我们正在使用 JpaRepository 连接 mysql。我们的存储库如下所示: public interface IRawEntityRepository extends JpaRepositor
我是一名优秀的程序员,十分优秀!