Java 无构造函数的MyBatis SQL查询

Java 无构造函数的MyBatis SQL查询,java,mybatis,ibatis,lombok,Java,Mybatis,Ibatis,Lombok,我试图用MyBatis编写一个SQL查询,从表中选择一堆字段,但不是全部字段 表格: CREATE TABLE metadata ( id BIGINT PRIMARY KEY, uuid VARCHAR(61) NOT NULL, original_name VARCHAR(255), file_size INTEGER NOT NULL, width INTEGER NOT NULL, height INTEGER NOT NULL,

我试图用MyBatis编写一个SQL查询,从表中选择一堆字段,但不是全部字段

表格:

CREATE TABLE metadata
(
    id BIGINT PRIMARY KEY,
    uuid VARCHAR(61) NOT NULL,
    original_name VARCHAR(255),
    file_size INTEGER NOT NULL,
    width INTEGER NOT NULL,
    height INTEGER NOT NULL,
    file_create_date TIMESTAMP WITH TIME ZONE,
    uploaded TIMESTAMP WITH TIME ZONE NOT NULL,
    title VARCHAR(255),
    status CHAR(1) NOT NULL DEFAULT 'I'
);
@Select("SELECT id, uuid FROM metadata WHERE status = 'A' AND uuid = #{uuid}")
Metadata getMetadata(@Param("uuid") String uuid);
org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: org.apache.ibatis.executor.ExecutorException: No constructor found in com.a.b.Metadata matching [java.lang.Long, java.lang.String]
### The error may exist in com/a/b/mapper/MetadataDao.java (best guess)
### The error may involve com.a.b..mapper.MetadataDao.getMetadata
### The error occurred while handling results
### SQL: SELECT id, uuid FROM metadata WHERE status = 'A' AND uuid = ?
### Cause: org.apache.ibatis.executor.ExecutorException: No constructor found in com.a.b.Metadata matching [java.lang.Long, java.lang.String]
MyBatis映射器:

CREATE TABLE metadata
(
    id BIGINT PRIMARY KEY,
    uuid VARCHAR(61) NOT NULL,
    original_name VARCHAR(255),
    file_size INTEGER NOT NULL,
    width INTEGER NOT NULL,
    height INTEGER NOT NULL,
    file_create_date TIMESTAMP WITH TIME ZONE,
    uploaded TIMESTAMP WITH TIME ZONE NOT NULL,
    title VARCHAR(255),
    status CHAR(1) NOT NULL DEFAULT 'I'
);
@Select("SELECT id, uuid FROM metadata WHERE status = 'A' AND uuid = #{uuid}")
Metadata getMetadata(@Param("uuid") String uuid);
org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: org.apache.ibatis.executor.ExecutorException: No constructor found in com.a.b.Metadata matching [java.lang.Long, java.lang.String]
### The error may exist in com/a/b/mapper/MetadataDao.java (best guess)
### The error may involve com.a.b..mapper.MetadataDao.getMetadata
### The error occurred while handling results
### SQL: SELECT id, uuid FROM metadata WHERE status = 'A' AND uuid = ?
### Cause: org.apache.ibatis.executor.ExecutorException: No constructor found in com.a.b.Metadata matching [java.lang.Long, java.lang.String]
但是我在myClass中找不到构造函数

我是否可以指示MyBatis以某种方式使用setter方法而不是带有输入参数的构造函数

我需要这种灵活性,因为我不想在编写带有稍微不同的结果集的新SQL查询或向SQL查询添加新字段时一直编写/修改构造函数

MyBatis例外情况:

CREATE TABLE metadata
(
    id BIGINT PRIMARY KEY,
    uuid VARCHAR(61) NOT NULL,
    original_name VARCHAR(255),
    file_size INTEGER NOT NULL,
    width INTEGER NOT NULL,
    height INTEGER NOT NULL,
    file_create_date TIMESTAMP WITH TIME ZONE,
    uploaded TIMESTAMP WITH TIME ZONE NOT NULL,
    title VARCHAR(255),
    status CHAR(1) NOT NULL DEFAULT 'I'
);
@Select("SELECT id, uuid FROM metadata WHERE status = 'A' AND uuid = #{uuid}")
Metadata getMetadata(@Param("uuid") String uuid);
org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: org.apache.ibatis.executor.ExecutorException: No constructor found in com.a.b.Metadata matching [java.lang.Long, java.lang.String]
### The error may exist in com/a/b/mapper/MetadataDao.java (best guess)
### The error may involve com.a.b..mapper.MetadataDao.getMetadata
### The error occurred while handling results
### SQL: SELECT id, uuid FROM metadata WHERE status = 'A' AND uuid = ?
### Cause: org.apache.ibatis.executor.ExecutorException: No constructor found in com.a.b.Metadata matching [java.lang.Long, java.lang.String]
更新


我正在使用生成getter/setter方法、生成器等,因此我不想手工编写构造函数。

元数据类中是否有空构造函数?这就是问题所在。我在POJO中添加了“@noargsconstuctor”(生成默认的空构造函数)和“@allargsconstuctor”(生成所有字段的构造函数),解决了这个问题。非常感谢。您能将问题标记为已回答吗?您的
元数据类中是否有空构造函数?这就是问题所在。我在POJO中添加了“@noargsconstuctor”(生成默认的空构造函数)和“@allargsconstuctor”(生成所有字段的构造函数),解决了这个问题。非常感谢。你能把问题标记为已回答吗?