I have a problem with MyBatis mapping. I have a domain class like this:
public class MyClass
{
private Long id;
private Date create;
private String content;
MyClass (Long id, Date create, String content)
{
this.id = id;
this.create = create;
this.content = content;
}
//getters and setters
A mapper class with a method like this:
@Select("SELECT * FROM MyTable WHERE id=#{id}")
MyClass getMyClass (@Param("id") Long id);
In the database the three columns are of type Number, Timestamp and Clob and have the same name as in the class fields.
When I use this method I get a: ExecutorException: No constructor found in [MyClass; matching [java.math.BigDecimal, java.sql.Timestamp, oracle.jdbc.OracleClob]
But if I remove the constructor from Myclass, then there is no problem at all. I would like to have the constructor, how can I fix it? I tried adding the @Results annotation in the mapper like so, but it didn't make any difference:
@Results(value = {
@Result(column = "id", property = "id", javaType = Long.class),
@Result(column = "create", property = "create", javaType = Date.class),
@Result(column = "content", property = "content", javaType = String.class)
})
MyBatis expects your model objects to have a no-arguments constructor (and possibly setters for each mapped field). Add those and everything should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With