小编C-S*_*ark的帖子

JPA鉴别器字段上的Spring-Data Pageable排序

我有一个JPA实体层次结构,JPA加入了继承:

@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "TYPE", discriminatorType = DiscriminatorType.STRING)
Product
Run Code Online (Sandbox Code Playgroud)

@Entity
@Table(name = "product_quiz")
@DiscriminatorValue("quiz")
public class QuizProduct extends Product
Run Code Online (Sandbox Code Playgroud)

我想用QueryByExample运行一个spring-data查询,PageRequest如下所示:

Example<Product> example = ...
PageRequest pageRequest = ...
Page<Product> productPage = productRepository.findAll(example, pageRequest);
Run Code Online (Sandbox Code Playgroud)

它工作正常,除非我设置sortFieldpageRequest"类型"(the @DiscriminatorColumn).

我试过:

  • 直接将类型字段添加到实体.这样查询运行正常,但持久化操作失败org.postgresql.util.PSQLException: The column index is out of range: 11, number of columns: 10.
  • 如果我纪念这一领域的@Transient,持续存在的作品,但查询给了我这样的例外:Unable to locate Attribute with the the given name [type] on this ManagedType [...AbstractEntityWithDate](AbstractEntityWithDate是@MappedSuperclass …

hibernate jpa spring-data spring-data-jpa

4
推荐指数
1
解决办法
886
查看次数

标签 统计

hibernate ×1

jpa ×1

spring-data ×1

spring-data-jpa ×1