【问题标题】:cannot find javax.persistence annotations when using spring r2dbc使用 spring r2dbc 时找不到 javax.persistence 注释
【发布时间】:2019-12-23 23:01:53
【问题描述】:

我正在尝试使用 H2Spring Boot 的反应式存储库。

我添加了依赖项

implementation 'org.springframework.boot.experimental:spring-boot-starter-data-r2dbc:0.1.0.M1'
implementation 'org.springframework.boot.experimental:spring-boot-actuator-autoconfigure-r2dbc:0.1.0.M1'
implementation 'io.r2dbc:r2dbc-pool:0.8.0.RELEASE'

我的域看起来像这样

@Entity
@Table(name = "json_comparison")
public class JsonComparisonResult {
    @Column(name = "comparison_id")
    @Id
    private String comparisonId;
    @Column(name = "left")
    private String leftSide;
    ....

何时依赖

implementation "org.springframework.boot:spring-boot-starter-data-jpa:$springBootVersion"

一切正常。但由于我添加了 r2dbc 依赖项,因此无法找到 javax.persistence 注释的任何依赖项。当我将starter-jpa 与反应式存储库一起使用时,它在启动时失败(常规Reactive Repositories are not supported by JPA)。

如何解决问题?手动添加javax.persistence依赖?

有什么问题?

【问题讨论】:

  • 但它说:“JPA 不支持反应式存储库”!?不支持 JPA,因为它不是响应式的
  • 我知道。问题是如何修复它,因为 JPA 提供了很多注释。到目前为止,我决定使用来自 Spring 框架库的 data.relational.core.mappingdata.annotation.Id 的注释。但是像Enumerated 这样的东西没有替代品
  • 所以你必须等到 JPA 也变得被动......
  • @SimonMartinelli 我只会玩弄现在存在的东西。当然不是为了生产。

标签: java spring h2 reactive spring-reactive


【解决方案1】:

作为解决方案,我决定改用org.springframework.data.relational.core.mapping 注释,例如@Table@Columnorg.springframework.data.annotation @Id

import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.Column;
import org.springframework.data.relational.core.mapping.Table;

此外,我必须通过 SQL 脚本手动创建表。

【讨论】:

  • 我也面临同样的问题。我们如何解决 Entity、JoinColumn、ManyToOne 等类的问题?我们应该使用哪个依赖项?
猜你喜欢
  • 2021-04-25
  • 2020-10-24
  • 2012-04-14
  • 1970-01-01
  • 1970-01-01
  • 2015-02-09
  • 2011-03-28
  • 1970-01-01
  • 2012-06-24
相关资源
最近更新 更多