java - Spring Data JPA : java. lang.NoSuchMethodException : java. util.List.<init>()

标签 java spring-data-jpa

我正在使用 Spring Data JPA 来创建服务。我正在尝试在 JPQL 查询中使用 IN 子句

实际上我正在尝试将此 LinQ 查询转换为 JPQL

LinQ 查询

from rooms in EspaceDB.Rooms
                            where roomIDList.Contains(rooms.nRoomID.ToString())
                            select rooms;

java.lang.NoSuchMethodException: userAuth.User.<init>()

这个解决方案对我来说不起作用。在我的所有模型类中,我都有默认构造函数。

JPQL 查询语法

@Query("select room from Room as room where room.nRoomId In (:nRoomIdList)")    
    List<Room> recoverDeletedRoom(@Param(value = "nRoomIdList") List<Integer> nRoomIdList);

控制台

java.lang.NoSuchMethodException: java.util.List.<init>()
    at java.lang.Class.getConstructor0(Unknown Source) ~[na:1.8.0_144]
    at java.lang.Class.getDeclaredConstructor(Unknown Source) ~[na:1.8.0_144]
    at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.createAttribute(ModelAttributeMethodProcessor.java:209) ~[spring-web-5.0.7.RELEASE.jar:5.0.7.RELEASE]

    at java.lang.Thread.run(Unknown Source) [na:1.8.0_144]

房间等级

@Entity
@Table(name = "room")
public class Room implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "room_seq_generator")
    @SequenceGenerator(name = "room_seq_generator", sequenceName = "room_seq",allocationSize=1)
    @Column(name = "nroom_id", columnDefinition="serial")   
    public Integer nRoomId;

    @Column(name = "ncampus_id")
    public Integer nCampusId;

     //....
     //....

     public Room() {
        super();
    }

房间 Controller

@PutMapping("/recoverDeletedRoom")
    public List<Room> recoverRoom(List<Integer> nRoomIdList, Boolean IsActive) {
        return roomService.recoverDeletedRoom(nRoomIdList, IsActive);
    }

最佳答案

更改您的@PutMapping代码

@PutMapping("/recoverDeletedRoom")
public List<Room> recoverRoom(@RequestBody WrapperObject wrapperObject) {
   return roomService.recoverDeletedRoom(wrapperObject.getNRoomIdList(), getIsActive());
}

并获取put映射体;

public class WrapperObject {

    List<Integer> nRoomIdList;
    Boolean isActive;

    //getters setters
}

关于java - Spring Data JPA : java. lang.NoSuchMethodException : java. util.List.<init>(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52629519/

相关文章:

java - 访问用户上的 LAZY 集合时出现 LazyInitializationException

java - 检测到死锁时 Hibernate session 不同步

mysql : why would I require AttributeConverter over enum to map a DB column having enum datatype as enum with a JPA entity?

database - 禁用外键取消引用 Hibernate

java - 如何从浏览器保存 .pdf?

Java 在不使用引号的情况下向 json 对象添加函数。

spring - 如何 Autowiring spring-data CrudRepository

java - OneToMany 主键列错误

java - 如果在 Spring Data JPA 中为 null,则跳过 @Param 作为 @Query 中的列表 : antlr. NoViableAltException:意外的 AST 节点

java - CRC-CCITT(克米特)