mybatis / mybatipse

Eclipse plugin adding support for MyBatis SQL Mapper Framework.
Eclipse Public License 1.0
333 stars 92 forks source link

Class/TypeAlias 'Order' not found ,multi-typeAliasesPackage problem on multi-datasource? #15

Open chenjch opened 10 years ago

chenjch commented 10 years ago
<bean id="sqlSessionFactory1" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="DataSource1" />
    <property name="configLocation" value="classpath:mybatis-config.xml" />
    <property name="typeAliasesPackage" value="com.abc.entity.a" />
    <property name="mapperLocations" value="classpath:mapper/a/*.xml" />
</bean>

<bean id="sqlSessionFactory2" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="DataSource2" />
    <property name="configLocation" value="classpath:mybatis-config.xml" />
    <property name="typeAliasesPackage" value="com.abc.entity.b" />
    <property name="mapperLocations" value="classpath:mapper/b/*.xml" />
</bean>

every mapper xml file in mapper/a/.xml is ok but every mapper xml file in mapper/b/.xml have error:

<select id="selectOrder" parameterType="String" resultType="Order">
    select sql...
</select>

Class/TypeAlias 'Order' not found.

harawata commented 10 years ago

Thank you for the report! That's a pretty tricky setting for MyBatipse :-) I'll see if there is a reasonable solution to such setting, but don't hold your breath.

harawata commented 10 years ago

In 1.0.7, I have changed the parsing logic when there are multiple SqlSessionFactoryBean declaration in a Spring config file.

In 1.0.6 and earlier, MyBatipse parses only the first bean to collect type aliases. In 1.0.7, MyBatipse parses all the beans.

This change should solve the error if... 1) there is no multiple classes with the same alias (e.g. entity.a.Order and entity.b.Order) or 2) there are multiple classes with the same alias, but their properties are the same.

Please let me know if 1.0.7 changes the situation...

Thank you, Iwao

akacd commented 8 years ago

Version 1.0.15 Using org.mybatis.spring.mapper.MapperScannerConfigurer

    <bean id="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
        <property name="basePackage" value="com.thinkgem.jeesite"/>
        <property name="annotationClass" value="com.thinkgem.jeesite.common.persistence.annotation.MyBatisDao"/>
    </bean>

Annotation:

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Documented
@Component
public @interface MyBatisDao {

    /**
     * The value may indicate a suggestion for a logical component name,
     * to be turned into a Spring bean in case of an autodetected component.
     * @return the suggested component name, if any
     */
    String value() default "";

}

There is no multiple classes with the same alias Interface is like this:

@MyBatisDao
public interface UserDao extends CrudDao<User> {
    public User getByLoginName(User user);
}
<select id="getByLoginName" resultType="User" parameterType="User">
        SELECT
            <include refid="userColumns"/>
        FROM sys_user a...

Multiple annotations found at this line:

harawata commented 8 years ago

Hi @akacd , Could you show me the bean definition of sqlSessionFactory ? MyBatipse couldn't resolve the type alias User, so I need to see how you define type aliases.

akacd commented 8 years ago

@harawata It's like this:

<!-- MyBatis begin -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  <property name="dataSource" ref="dataSource"/>
  <property name="typeAliasesPackage" value="com.thinkgem.jeesite"/>
  <property name="typeAliasesSuperType" value="com.thinkgem.jeesite.common.persistence.BaseEntity"/>
  <property name="mapperLocations" value="classpath:/mappings/**/*.xml"/>
  <property name="configLocation" value="classpath:/mybatis-config.xml"></property>
</bean>`

image

harawata commented 8 years ago

Ah...there is a bug in type alias search :stuck_out_tongue_closed_eyes:

As it's a different problem than #15, I have created a new issue #42 . Thanks for the help!