Skip to content

Commit d55081b

Browse files
authored
BAEL-3809: Ensure tables are dropped in proper order (#8640)
1 parent d0225e5 commit d55081b

9 files changed

Lines changed: 39 additions & 22 deletions

File tree

pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,7 @@
659659
<module>spring-boot-mvc-2</module>
660660
<module>spring-boot-nashorn</module>
661661
<module>spring-boot-parent</module>
662+
<module>spring-boot-performance</module>
662663
<module>spring-boot-property-exp</module>
663664

664665
<module>spring-boot-rest</module>
@@ -1187,6 +1188,7 @@
11871188
<module>spring-boot-mvc-2</module>
11881189
<module>spring-boot-nashorn</module>
11891190
<module>spring-boot-parent</module>
1191+
<module>spring-boot-performance</module>
11901192
<module>spring-boot-property-exp</module>
11911193

11921194
<module>spring-boot-rest</module>

spring-boot-modules/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
<!-- <module>spring-boot-gradle</module> --> <!-- Not a maven project -->
2323
<module>spring-boot-keycloak</module>
2424
<module>spring-boot-mvc-birt</module>
25-
<module>spring-boot-performance</module>
2625
<module>spring-boot-properties</module>
2726
<module>spring-boot-springdoc</module>
2827
<module>spring-boot-testing</module>
File renamed without changes.

spring-boot-modules/spring-boot-performance/pom.xml renamed to spring-boot-performance/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<groupId>com.baeldung</groupId>
1212
<artifactId>parent-boot-2</artifactId>
1313
<version>0.0.1-SNAPSHOT</version>
14-
<relativePath>../../parent-boot-2</relativePath>
14+
<relativePath>../parent-boot-2</relativePath>
1515
</parent>
1616

1717
<dependencies>

spring-boot-modules/spring-boot-performance/src/main/java/com/baeldung/lazyinitialization/Application.java renamed to spring-boot-performance/src/main/java/com/baeldung/lazyinitialization/Application.java

File renamed without changes.

spring-boot-modules/spring-boot-performance/src/main/java/com/baeldung/lazyinitialization/services/Writer.java renamed to spring-boot-performance/src/main/java/com/baeldung/lazyinitialization/services/Writer.java

File renamed without changes.

spring-boot-modules/spring-boot-performance/src/main/resources/application.yml renamed to spring-boot-performance/src/main/resources/application.yml

File renamed without changes.

spring-security-modules/spring-security-mvc-boot/src/main/java/com/baeldung/models/Tweet.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,26 @@
33
import java.util.HashSet;
44
import java.util.Set;
55

6+
import javax.persistence.CollectionTable;
67
import javax.persistence.ElementCollection;
78
import javax.persistence.Entity;
89
import javax.persistence.FetchType;
910
import javax.persistence.GeneratedValue;
1011
import javax.persistence.GenerationType;
1112
import javax.persistence.Id;
13+
import javax.persistence.Table;
1214

1315
@Entity
16+
@Table(name = "Tweet")
1417
public class Tweet {
1518
@Id
1619
@GeneratedValue(strategy = GenerationType.SEQUENCE)
1720
private long id;
1821
private String tweet;
1922
private String owner;
2023
@ElementCollection(targetClass = String.class, fetch = FetchType.EAGER)
21-
private Set<String> likes = new HashSet();
24+
@CollectionTable(name = "Tweet_Likes")
25+
private Set<String> likes = new HashSet<>();
2226

2327
public long getId() {
2428
return id;

spring-security-modules/spring-security-mvc-boot/src/test/java/com/baeldung/relationships/SpringDataWithSecurityIntegrationTest.java

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
package com.baeldung.relationships;
22

3-
import static org.springframework.util.Assert.isTrue;
4-
5-
import java.util.Date;
6-
import java.util.List;
7-
8-
import javax.servlet.ServletContext;
9-
10-
import org.junit.AfterClass;
3+
import com.baeldung.AppConfig;
4+
import com.baeldung.data.repositories.TweetRepository;
5+
import com.baeldung.data.repositories.UserRepository;
6+
import com.baeldung.models.AppUser;
7+
import com.baeldung.models.Tweet;
8+
import com.baeldung.security.AppUserPrincipal;
9+
import com.baeldung.util.DummyContentUtil;
10+
import org.junit.After;
1111
import org.junit.Before;
1212
import org.junit.Test;
1313
import org.junit.runner.RunWith;
1414
import org.springframework.beans.factory.annotation.Autowired;
1515
import org.springframework.dao.InvalidDataAccessApiUsageException;
1616
import org.springframework.data.domain.Page;
1717
import org.springframework.data.domain.PageRequest;
18+
import org.springframework.jdbc.core.JdbcTemplate;
1819
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
1920
import org.springframework.security.core.Authentication;
2021
import org.springframework.security.core.context.SecurityContextHolder;
2122
import org.springframework.test.annotation.DirtiesContext;
2223
import org.springframework.test.context.ContextConfiguration;
2324
import org.springframework.test.context.junit4.SpringRunner;
2425
import org.springframework.test.context.web.WebAppConfiguration;
26+
import org.springframework.test.jdbc.JdbcTestUtils;
2527
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
2628

27-
import com.baeldung.AppConfig;
28-
import com.baeldung.data.repositories.TweetRepository;
29-
import com.baeldung.data.repositories.UserRepository;
30-
import com.baeldung.models.AppUser;
31-
import com.baeldung.models.Tweet;
32-
import com.baeldung.security.AppUserPrincipal;
33-
import com.baeldung.util.DummyContentUtil;
29+
import javax.servlet.ServletContext;
30+
import java.util.Date;
31+
import java.util.List;
32+
33+
import static org.springframework.util.Assert.isTrue;
3434

3535
@RunWith(SpringRunner.class)
3636
@WebAppConfiguration
@@ -54,10 +54,22 @@ public void testInit() {
5454
tweetRepository.saveAll(DummyContentUtil.generateDummyTweets(appUsers));
5555
}
5656

57-
@AfterClass
58-
public static void tearDown() {
59-
tweetRepository.deleteAll();
60-
userRepository.deleteAll();
57+
/**
58+
* This is to ensure the tables are dropped in proper order.
59+
* After the Spring Boot 2.2.2 upgrade, DDL statements generated automatically try to drop Tweet table first.
60+
* As a result we get org.h2.jdbc.JdbcSQLSyntaxErrorException because Tweet_Likes table depends on Tweet.
61+
*
62+
* @see <a href="https://stackoverflow.com/questions/59364212/integrationtest-isolation-fails-in-springboot-2-2-2-release-error-dopping-table">
63+
* StackOverflow#59364212
64+
* </a>
65+
* @see <a href="https://stackoverflow.com/questions/59561551/hibernate-h2-specify-drop-table-order">
66+
* StackOverflow#59561551
67+
* </a>
68+
*/
69+
@After
70+
public void tearDown() {
71+
JdbcTemplate jdbcTemplate = ctx.getBean(JdbcTemplate.class);
72+
JdbcTestUtils.dropTables(jdbcTemplate, "Tweet_Likes", "Tweet");
6173
}
6274

6375
@Test

0 commit comments

Comments
 (0)