From ec66c8960b457bcd71d6773217c21cde20b577ce Mon Sep 17 00:00:00 2001 From: yulei Date: Sun, 4 Oct 2015 00:44:05 +0800 Subject: [PATCH] fix #64 set databaseId before parse mapper xmls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit when parse mapper xml files , it needs to know what databaseId is。 org.apache.ibatis.builder.xml.XMLConfigBuilder'smethod:databaseIdProviderElement,will set databaseId if "environment != null && databaseIdProvider != null",but the configuration's environment is null becase it will set after "xmlConfigBuilder.parse();" in file "SqlSessionFactoryBean.java" --- .../mybatis/spring/SqlSessionFactoryBean.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/mybatis/spring/SqlSessionFactoryBean.java b/src/main/java/org/mybatis/spring/SqlSessionFactoryBean.java index 30dff45c50..8b399b3cc5 100644 --- a/src/main/java/org/mybatis/spring/SqlSessionFactoryBean.java +++ b/src/main/java/org/mybatis/spring/SqlSessionFactoryBean.java @@ -425,7 +425,15 @@ protected SqlSessionFactory buildSqlSessionFactory() throws IOException { } } } - + + if (this.databaseIdProvider != null) {//fix #64 set databaseId before parse mapper xmls + try { + configuration.setDatabaseId(this.databaseIdProvider.getDatabaseId(this.dataSource)); + } catch (SQLException e) { + throw new NestedIOException("Failed getting a databaseId", e); + } + } + if (xmlConfigBuilder != null) { try { xmlConfigBuilder.parse(); @@ -446,14 +454,6 @@ protected SqlSessionFactory buildSqlSessionFactory() throws IOException { configuration.setEnvironment(new Environment(this.environment, this.transactionFactory, this.dataSource)); - if (this.databaseIdProvider != null) { - try { - configuration.setDatabaseId(this.databaseIdProvider.getDatabaseId(this.dataSource)); - } catch (SQLException e) { - throw new NestedIOException("Failed getting a databaseId", e); - } - } - if (!isEmpty(this.mapperLocations)) { for (Resource mapperLocation : this.mapperLocations) { if (mapperLocation == null) {