Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
chenjch opened this issue Jun 3, 2014 · 6 comments

Comments

@chenjch
Copy link

chenjch commented Jun 3, 2014

<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
Copy link
Member

harawata commented Jun 5, 2014

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 added a commit that referenced this issue Oct 5, 2014
@harawata
Copy link
Member

harawata commented Oct 5, 2014

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
Copy link

akacd commented Apr 2, 2016

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:
- Class/TypeAlias 'User' not found.

@harawata
Copy link
Member

harawata commented Apr 2, 2016

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
Copy link

akacd commented Apr 3, 2016

@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
Copy link
Member

harawata commented Apr 3, 2016

Ah...there is a bug in type alias search 😝

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants