mybatis / generator

A code generator for MyBatis.
http://www.mybatis.org/generator/
5.29k stars 2.52k forks source link

There is no getter for property named 'distinct' in 'class com.xxx.domain.SysUserExample$Criteria #717

Closed zhoulei4652 closed 3 years ago

zhoulei4652 commented 3 years ago

SysUserMapper.java in dao layer one of generated method as below

List<SysUser> selectByExample(SysUserExample.Criteria example);

when I invoke this method, it will throw below execption

There is no getter for property named 'distinct' in 'class com.xxx.domain.SysUserExample$Criteria

I need to manully modify parameter from SysUserExample.Criteria example to SysUserExample example

and then, it will run properly.

my test code

    @Test
    public void testGeneratorMyBatis3Simple() throws IOException {
        InputStream resource = Resources.getResourceAsStream("sqlMapConfig.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resource);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        SysUserMapper mapper = sqlSession.getMapper(SysUserMapper.class);
        // SysUser sysUser = mapper.selectByPrimaryKey((long) 30);

        SysUserExample example = new SysUserExample();
        SysUserExample.Criteria criteria = example.createCriteria();
        criteria.andEmailEqualTo("126.com");
       // List<SysUser> users = mapper.selectByExample(example);
        List<SysUser> users = mapper.selectByExample(criteria);
        System.out.println(users);
        sqlSession.close();
    }

mybatis: 3.4.5 mybaits-generator: 1.4.0

zhoulei4652 commented 3 years ago

this is my generatroConfig.xml

<!DOCTYPE generatorConfiguration PUBLIC
        "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
        "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
    <context id="simple" targetRuntime="MyBatis3">

        <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/test" userId="root" password="123456" />

        <javaModelGenerator targetPackage="com.xxx.domain" targetProject="src/main/java"/>

        <sqlMapGenerator targetPackage="com/xxx/dao" targetProject="src/main/resources" />

        <javaClientGenerator type="XMLMAPPER" targetPackage="com.xxx.dao" targetProject="src/main/java"/>

        <table tableName="sys_user" />

    </context>
</generatorConfiguration>
jeffgbutler commented 3 years ago

As you have seen, the "distinct" property is in the Example class - not the Criteria class.

Are you using any generator plugins? By default the generator creates selectByExample(XXXExample example) methods, not selectByExample(XXXExample.Criteria example) - this has been true for years.

zhoulei4652 commented 3 years ago

you are right, the code was modified by other plugins.

thanks for your timely response and support.