Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/331.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 使用@Query时的Wierd-Spring JPA行为_Java_Spring Data Jpa - Fatal编程技术网

Java 使用@Query时的Wierd-Spring JPA行为

Java 使用@Query时的Wierd-Spring JPA行为,java,spring-data-jpa,Java,Spring Data Jpa,@Query annotation现在有点奇怪,我正在尝试使用用户列表作为输入从表中检索一些特定字段: @Query(value = "select new document(documentId, documentType, status, rejected) " + "from document where user in ?1") List<Document> findByUserInWithoutFiles(List<User&

@Query annotation现在有点奇怪,我正在尝试使用用户列表作为输入从表中检索一些特定字段:

@Query(value = "select new document(documentId, documentType, status, rejected) " + "from document where user in ?1") 
List<Document> findByUserInWithoutFiles(List<User> users);
所以问题是我做错了什么?这是虫子吗

是否有其他方法从该对象获取部分信息?(我不需要文件字段)

如果您有任何建议,我将不胜感激

干杯

编辑:我做了一些备选方案研究,最终使用了基于接口的投影,而不是@Query annotation,这是一个更好、更优雅的解决方案


我做了一些备选方案研究,最终使用了基于接口的投影,而不是@Query annotation,这是一个更好、更优雅的解决方案

@Query(value = "select new document(documentId, documentType, status, rejected, user) " + "from document where user in ?1")
List<Document> findByUserInWithoutFiles(List<User> users);
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity(name = "document")
@Table(name = "document", schema = "foo")
public class Document implements Serializable {

  private static final long serialVersionUID = -9793924073464282L;

  @GeneratedValue(generator = "uuid2")
  @GenericGenerator(name = "uuid2", strategy = "uuid2")
  @Column(columnDefinition = "BINARY(16)", name = "document_id")
  @Id
  private UUID documentId;
  @Column(name = "document_type")
  private PhotoEnum documentType;
  @Column(name = "created_date")
  private LocalDateTime createdDate;
  @Column(name = "update_date")
  private LocalDateTime updateDate;
  @Lob
  @Column(name = "file", columnDefinition = "BLOB")
  private byte[] file;
  @Column(name = "status")
  private String status;
  @Column(name = "rejected")
  private String rejected;
  @Column(name = "expiration_date")
  private LocalDate expirationDate;
  @ManyToOne(targetEntity = User.class, fetch = FetchType.LAZY)
  @JoinColumn(name = "user_id")
  private User user;

  public Document(PhotoEnum documentType) {
    this.documentType = documentType;
  }

  public Document(UUID documentId, PhotoEnum documentType, String status, String rejected,
      User user) {
    this.documentId = documentId;
    this.documentType = documentType;
    this.status = status;
    this.rejected = rejected;
    this.user = user;
    }