Skip to content

Commit ec66c89

Browse files
committed
fix mybatis#64 set databaseId before parse mapper xmls
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"
1 parent c5834f9 commit ec66c89

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/main/java/org/mybatis/spring/SqlSessionFactoryBean.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,15 @@ protected SqlSessionFactory buildSqlSessionFactory() throws IOException {
425425
}
426426
}
427427
}
428-
428+
429+
if (this.databaseIdProvider != null) {//fix #64 set databaseId before parse mapper xmls
430+
try {
431+
configuration.setDatabaseId(this.databaseIdProvider.getDatabaseId(this.dataSource));
432+
} catch (SQLException e) {
433+
throw new NestedIOException("Failed getting a databaseId", e);
434+
}
435+
}
436+
429437
if (xmlConfigBuilder != null) {
430438
try {
431439
xmlConfigBuilder.parse();
@@ -446,14 +454,6 @@ protected SqlSessionFactory buildSqlSessionFactory() throws IOException {
446454

447455
configuration.setEnvironment(new Environment(this.environment, this.transactionFactory, this.dataSource));
448456

449-
if (this.databaseIdProvider != null) {
450-
try {
451-
configuration.setDatabaseId(this.databaseIdProvider.getDatabaseId(this.dataSource));
452-
} catch (SQLException e) {
453-
throw new NestedIOException("Failed getting a databaseId", e);
454-
}
455-
}
456-
457457
if (!isEmpty(this.mapperLocations)) {
458458
for (Resource mapperLocation : this.mapperLocations) {
459459
if (mapperLocation == null) {

0 commit comments

Comments
 (0)