Skip to content

Commit a2e3b93

Browse files
authored
Merge pull request #255 from Toparvion/fix-h2-sql-error
Fix H2 SQL error in JDBC mode
2 parents 117c867 + ff80e67 commit a2e3b93

File tree

7 files changed

+74
-15
lines changed

7 files changed

+74
-15
lines changed

src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRepositoryImpl.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@
1515
*/
1616
package org.springframework.samples.petclinic.repository.jdbc;
1717

18+
import java.sql.ResultSet;
19+
import java.sql.SQLException;
20+
import java.util.Collection;
21+
import java.util.Date;
22+
import java.util.HashMap;
23+
import java.util.List;
24+
import java.util.Map;
25+
26+
import javax.sql.DataSource;
27+
1828
import org.springframework.context.annotation.Profile;
1929
import org.springframework.dao.DataAccessException;
2030
import org.springframework.dao.EmptyResultDataAccessException;
@@ -30,11 +40,6 @@
3040
import org.springframework.samples.petclinic.repository.VisitRepository;
3141
import org.springframework.stereotype.Repository;
3242

33-
import javax.sql.DataSource;
34-
import java.sql.ResultSet;
35-
import java.sql.SQLException;
36-
import java.util.*;
37-
3843
/**
3944
* A simple JDBC-based implementation of the {@link VisitRepository} interface.
4045
*
@@ -114,7 +119,7 @@ public Visit findById(int id) throws DataAccessException {
114119
public Collection<Visit> findAll() throws DataAccessException {
115120
Map<String, Object> params = new HashMap<>();
116121
return this.namedParameterJdbcTemplate.query(
117-
"SELECT id as visit_id, pets.id as pets_id, visit_date, description FROM visits LEFT JOIN pets ON visits.pet_id = pets.id",
122+
"SELECT visits.id as visit_id, pets.id as pets_id, visit_date, description FROM visits LEFT JOIN pets ON visits.pet_id = pets.id",
118123
params, new JdbcVisitRowMapperExt());
119124
}
120125

src/main/resources/application.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ server.servlet.context-path=/petclinic/
2828
spring.sql.init.platform=h2
2929
# Ensures schema & data reload on every restart (good for local dev)
3030
spring.sql.init.mode=always
31-
spring.sql.init.schema-locations=classpath*:db/${platform}/schema.sql
32-
spring.sql.init.data-locations=classpath*:db/${platform}/data.sql
31+
spring.sql.init.schema-locations=classpath*:db/${spring.sql.init.platform}/schema.sql
32+
spring.sql.init.data-locations=classpath*:db/${spring.sql.init.platform}/data.sql
3333

3434
spring.messages.basename=messages/messages
3535
spring.jpa.open-in-view=false
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2002-2013 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.samples.petclinic.service.clinicService;
17+
18+
import org.springframework.boot.test.context.SpringBootTest;
19+
import org.springframework.test.context.ActiveProfiles;
20+
import org.springframework.test.context.TestPropertySource;
21+
22+
/**
23+
* <p> Integration test using the JDBC and H2 profiles.
24+
*
25+
* @author Thomas Risberg
26+
* @author Michael Isvy
27+
* @see AbstractClinicServiceTests AbstractClinicServiceTests for more details. </p>
28+
*/
29+
@SpringBootTest
30+
@ActiveProfiles({"h2", "jdbc"})
31+
@TestPropertySource(properties = {
32+
"spring.sql.init.platform=h2",
33+
"spring.h2.console.enabled=false"
34+
})
35+
class ClinicServiceH2JdbcTests extends AbstractClinicServiceTests {
36+
37+
}

src/test/java/org/springframework/samples/petclinic/service/clinicService/ClinicServiceJdbcTests.java renamed to src/test/java/org/springframework/samples/petclinic/service/clinicService/ClinicServiceHsqlJdbcTests.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@
1717

1818
import org.springframework.boot.test.context.SpringBootTest;
1919
import org.springframework.test.context.ActiveProfiles;
20+
import org.springframework.test.context.TestPropertySource;
2021

2122
/**
22-
* <p> Integration test using the jdbc profile.
23+
* <p> Integration test using the JDBC and HSQLDB profiles.
2324
*
2425
* @author Thomas Risberg
2526
* @author Michael Isvy
2627
* @see AbstractClinicServiceTests AbstractClinicServiceTests for more details. </p>
2728
*/
2829
@SpringBootTest
29-
@ActiveProfiles({"jdbc", "hsqldb"})
30-
class ClinicServiceJdbcTests extends AbstractClinicServiceTests {
30+
@ActiveProfiles({"hsqldb", "jdbc"})
31+
@TestPropertySource(properties = {"spring.sql.init.platform=hsqldb"})
32+
class ClinicServiceHsqlJdbcTests extends AbstractClinicServiceTests {
3133

3234
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.springframework.samples.petclinic.service.userService;
2+
3+
import org.springframework.boot.test.context.SpringBootTest;
4+
import org.springframework.test.context.ActiveProfiles;
5+
import org.springframework.test.context.TestPropertySource;
6+
7+
@SpringBootTest
8+
@ActiveProfiles({"h2", "jdbc"})
9+
@TestPropertySource(properties = {
10+
"spring.sql.init.platform=h2",
11+
"spring.h2.console.enabled=false"
12+
})
13+
class UserServiceH2JdbcTests extends AbstractUserServiceTests {
14+
15+
}

src/test/java/org/springframework/samples/petclinic/service/userService/UserServiceJdbcTests.java renamed to src/test/java/org/springframework/samples/petclinic/service/userService/UserServiceHsqlJdbcTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import org.springframework.test.context.ActiveProfiles;
55

66
@SpringBootTest
7-
@ActiveProfiles({"jdbc", "hsqldb"})
8-
class UserServiceJdbcTests extends AbstractUserServiceTests {
7+
@ActiveProfiles({"hsqldb", "jdbc"})
8+
class UserServiceHsqlJdbcTests extends AbstractUserServiceTests {
99

1010
}

src/test/resources/application.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ server.servlet.context-path=/petclinic/
2525
spring.jpa.open-in-view=false
2626

2727
# database init
28-
spring.sql.init.schema-locations=classpath*:db/hsqldb/schema.sql
29-
spring.sql.init.data-locations=classpath*:db/hsqldb/data.sql
28+
spring.sql.init.schema-locations=classpath*:db/${spring.sql.init.platform}/schema.sql
29+
spring.sql.init.data-locations=classpath*:db/${spring.sql.init.platform}/data.sql
3030

3131
spring.messages.basename=messages/messages
3232
logging.level.org.springframework=INFO

0 commit comments

Comments
 (0)