Closed peter-urbanus closed 2 years ago
Thank you for the report, @peter-urbanus !
A few quick things that might fix the problem:
If none of them didn't resolve the issue, please try the followings and let me know the results:
Hi @Hirawate, sorry for taking so long to respond. I recently installed MyBatipse and I have the same problem. I tried all your suggestions with no result. I also imported the jpetstore project, and it didn't have any errors. However, this may be because jpetstore doesn't use any <resultMap>. I do have some news though: I have the errors in a handwritten mapper.xml file, but in xml generated by MyBatis Generator, which uses <resultMap>, there are no errors!. Both mappers are in the same project.
Again as previously, the errors went away after I uninstalled MyBatipse
You can ask me anything :-)
Here is the XML of the mapper that has the errors:
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="pu.heavymetal.dal.queries.QueriesMapper">
<resultMap id="jaarDocument" type="pu.heavymetal.bo.JaarDocument">
<result property="jaar" column="JAAR" jdbcType="INTEGER"/>
<result property="issues" column="ISSUES" jdbcType="INTEGER"/>
</resultMap>
Here, both properties can't be found with a message like this: Property 'jaar' not found in class pu.heavymetal.bo.JaarDocument
. Here is the generated XML that has no errors:
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="pu.heavymetal.dal.generated.AuteurDalMapper">
<resultMap id="BaseResultMap" type="pu.heavymetal.dal.generated.AuteurDal">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="naam" jdbcType="VARCHAR" property="naam" />
</resultMap>
Do you want me to show the java code?
Thanks for the info @purbanus ,
Try copying the BaseResultMap
in the OK mapper and paste it into the NG mapper (i.e. QueriesMapper
) and see if MyBatipse reports the error or not.
Ok, I did that, and it gives no errors! Here is the XML:
<mapper namespace="pu.heavymetal.dal.queries.QueriesMapper">
<resultMap id="BaseResultMap" type="pu.heavymetal.dal.generated.AuteurDal">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="naam" jdbcType="VARCHAR" property="naam" />
</resultMap>
<resultMap id="jaarDocument" type="pu.heavymetal.bo.JaarDocument">
<result property="jaar" column="JAAR" jdbcType="INTEGER"/>
<result property="issues" column="ISSUES" jdbcType="INTEGER"/>
</resultMap>
So the BaseResultMap has no errors, the jaarDocument has two. I still have no idea.
One step closer. :) Now we know that the difference lies between those two classes.
It is worth checking the directory structure in Finder/File Explorer. It should look like this:
But sometimes, users create a directory (i.e. package) that contains a dot.
It could be something else, but compare these classes carefully and you'll find the answer.
I'm afraid not. Here is a screenshot of the directory structure
It's Eclipse, right? Did you check it in the system's file explorer?
This is indeed Eclipse. Here is the same screenshot of the file system:
Well, could you post the content of JaarDocument.java
?
Sure, there you go
package pu.heavymetal.bo;
public class JaarDocument
{
private final int jaar;
private final long issues;
public JaarDocument( Integer aJaar, Long aIssues )
{
super();
jaar = aJaar;
issues = aIssues;
}
public int getJaar()
{
return jaar;
}
public long getIssues()
{
return issues;
}
}
Oh, now I see: it's the final
in the member definitions. If I remove that the errors go away!
In that case, you need to use 'constructor mapping'.
<resultMap id="jaarDocument" type="pu.heavymetal.bo.JaarDocument">
<constructor>
<arg column="JAAR" javaType="java.lang.Integer" />
<arg column="ISSUES" javaType="java.lang.Long" />
</constructor>
</resultMap>
The types of constructor args should match the field types, BTW.
Please see the doc for the details. https://mybatis.org/mybatis-3/sqlmap-xml.html#constructor
That seems to solve the problem. However, MyBatis has no problem using the immutable class, it's only MyBatipse that has a problem with that. If I uninstall MyBatipse everything runs fine, and there aren't any errors in the XML.
MyBatis sets values to final fields using reflection, but you really should not rely on that 'feature' as JDK gets stricter.
Ok, I will accept your answer as the final
answer, so you can close the problem. Thanks a lot for your time!
Thank you for taking the time to report the issue! 👍
For instance, these properties were al marked with error:
And this is part of the class in question
As you can see, all the properties are there. The errors went away after I uninstalled MyBatipse.