JAVA-220644 | Upgrade spring-boot-persistence-h2 to Spring Boot 3 (#14998)
This commit is contained in:
committed by
GitHub
parent
835cb8e15c
commit
106067388d
+2
-2
@@ -1,7 +1,7 @@
|
||||
package com.baeldung.h2.exceptions.models;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
|
||||
@Entity
|
||||
public class User {
|
||||
|
||||
+2
-2
@@ -3,15 +3,15 @@ package com.baeldung.h2db.demo.client;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import javax.annotation.PostConstruct;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
|
||||
@SpringBootApplication
|
||||
@ComponentScan("com.baeldung.h2db.demo.client")
|
||||
public class ClientSpringBootApp {
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ package com.baeldung.h2db.demo.server;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import javax.annotation.PostConstruct;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import org.h2.tools.Server;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
|
||||
+4
-2
@@ -1,13 +1,14 @@
|
||||
package com.baeldung.h2db.lazy_load_no_trans.entity;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.annotations.Immutable;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
|
||||
@Entity
|
||||
@Getter
|
||||
@@ -22,5 +23,6 @@ public class Document {
|
||||
|
||||
private String title;
|
||||
|
||||
@Column(name="user_id")
|
||||
private Long userId;
|
||||
}
|
||||
|
||||
+4
-4
@@ -8,10 +8,10 @@ import org.hibernate.annotations.Fetch;
|
||||
import org.hibernate.annotations.FetchMode;
|
||||
import org.hibernate.annotations.Immutable;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToMany;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
+5
-4
@@ -1,9 +1,10 @@
|
||||
package com.baeldung.h2db.notnull.models;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Entity
|
||||
|
||||
+4
-4
@@ -1,9 +1,9 @@
|
||||
package com.baeldung.h2db.springboot.models;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
import java.util.Objects;
|
||||
|
||||
@Table(name = "countries")
|
||||
|
||||
@@ -4,9 +4,9 @@ insert into "user" values (103, 'user3', 'comment3');
|
||||
insert into "user" values (104, 'user4', 'comment4');
|
||||
insert into "user" values (105, 'user5', 'comment5');
|
||||
|
||||
insert into "document" values (1, 'doc1', 101);
|
||||
insert into "document" values (2, 'doc2', 101);
|
||||
insert into "document" values (3, 'doc3', 101);
|
||||
insert into "document" values (4, 'doc4', 101);
|
||||
insert into "document" values (5, 'doc5', 102);
|
||||
insert into "document" values (6, 'doc6', 102);
|
||||
insert into "document" ("id","title","user_id") values (1, 'doc1', 101);
|
||||
insert into "document" ("id","title","user_id") values (2, 'doc2', 101);
|
||||
insert into "document" ("id","title","user_id") values (3, 'doc3', 101);
|
||||
insert into "document" ("id","title","user_id") values (4, 'doc4', 101);
|
||||
insert into "document" ("id","title","user_id") values (5, 'doc5', 102);
|
||||
insert into "document" ("id","title","user_id") values (6, 'doc6', 102);
|
||||
+6
-5
@@ -2,16 +2,17 @@ package com.baeldung.h2db.notnull;
|
||||
|
||||
import com.baeldung.h2db.notnull.daos.ItemRepository;
|
||||
import com.baeldung.h2db.notnull.models.Item;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import javax.validation.ConstraintViolationException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
import jakarta.validation.ConstraintViolationException;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = NotNullVsNullableApplication.class)
|
||||
public class ItemIntegrationTest {
|
||||
@@ -21,8 +22,8 @@ public class ItemIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void shouldNotAllowToPersistNullItemsPrice() {
|
||||
assertThatThrownBy(() -> itemRepository.save(new Item()))
|
||||
.hasRootCauseInstanceOf(ConstraintViolationException.class)
|
||||
.hasStackTraceContaining("must not be null");
|
||||
assertThatThrownBy(() -> itemRepository.save(new Item())).hasRootCauseInstanceOf(ConstraintViolationException.class)
|
||||
.hasStackTraceContaining("propertyPath=price")
|
||||
.hasStackTraceContaining("null");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user