Merge branch 'master' into master
This commit is contained in:
@@ -16,6 +16,38 @@
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<!-- JBoss distributes a complete set of Java EE 7 APIs including a Bill of Materials (BOM).
|
||||
A BOM specifies the versions of a "stack" (or a collection) of artifacts. We use this here so that we
|
||||
always get the correct versions of artifacts. Here we use the jboss-javaee-7.0-with-tools stack (you
|
||||
can read this as the JBoss stack of the Java EE 7 APIs, with some extras tools for your project, such
|
||||
as Arquillian for testing) and the jboss-javaee-7.0-with-hibernate stack you can read this as the JBoss
|
||||
stack of the Java EE 7 APIs, with extras from the Hibernate family of projects) -->
|
||||
<dependency>
|
||||
<groupId>org.wildfly.bom</groupId>
|
||||
<artifactId>jboss-javaee-7.0-with-tools</artifactId>
|
||||
<version>${jboss.bom.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wildfly.bom</groupId>
|
||||
<artifactId>jboss-javaee-7.0-with-hibernate</artifactId>
|
||||
<version>${jboss.bom.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.deltaspike.distribution</groupId>
|
||||
<artifactId>distributions-bom</artifactId>
|
||||
<version>${deltaspike.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<!-- First declare the APIs we depend on and need for compilation. All of them are provided by
|
||||
JBoss WildFly -->
|
||||
@@ -245,38 +277,6 @@
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<!-- JBoss distributes a complete set of Java EE 7 APIs including a Bill of Materials (BOM).
|
||||
A BOM specifies the versions of a "stack" (or a collection) of artifacts. We use this here so that we
|
||||
always get the correct versions of artifacts. Here we use the jboss-javaee-7.0-with-tools stack (you
|
||||
can read this as the JBoss stack of the Java EE 7 APIs, with some extras tools for your project, such
|
||||
as Arquillian for testing) and the jboss-javaee-7.0-with-hibernate stack you can read this as the JBoss
|
||||
stack of the Java EE 7 APIs, with extras from the Hibernate family of projects) -->
|
||||
<dependency>
|
||||
<groupId>org.wildfly.bom</groupId>
|
||||
<artifactId>jboss-javaee-7.0-with-tools</artifactId>
|
||||
<version>${jboss.bom.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wildfly.bom</groupId>
|
||||
<artifactId>jboss-javaee-7.0-with-hibernate</artifactId>
|
||||
<version>${jboss.bom.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.deltaspike.distribution</groupId>
|
||||
<artifactId>distributions-bom</artifactId>
|
||||
<version>${deltaspike.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<properties>
|
||||
<querydsl.version>3.7.4</querydsl.version>
|
||||
<deltaspike.version>1.8.2</deltaspike.version>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0"?>
|
||||
<project
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>hibernate-enterprise</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
package com.baeldung.hibernate.exception.transientobject;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import com.baeldung.hibernate.exception.transientobject.entity.Address;
|
||||
import com.baeldung.hibernate.exception.transientobject.entity.Department;
|
||||
import com.baeldung.hibernate.exception.transientobject.entity.Author;
|
||||
import com.baeldung.hibernate.exception.transientobject.entity.Book;
|
||||
import com.baeldung.hibernate.exception.transientobject.entity.Employee;
|
||||
import com.baeldung.hibernate.exception.transientobject.entity.User;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
|
||||
public class HibernateUtil {
|
||||
private static SessionFactory sessionFactory;
|
||||
|
||||
public static SessionFactory getSessionFactory() {
|
||||
if (sessionFactory == null) {
|
||||
try {
|
||||
Configuration configuration = new Configuration();
|
||||
Properties settings = new Properties();
|
||||
settings.put(Environment.DRIVER, "org.hsqldb.jdbcDriver");
|
||||
settings.put(Environment.URL, "jdbc:hsqldb:mem:transient");
|
||||
settings.put(Environment.USER, "sa");
|
||||
settings.put(Environment.PASS, "");
|
||||
settings.put(Environment.DIALECT, "org.hibernate.dialect.HSQLDialect");
|
||||
settings.put(Environment.SHOW_SQL, "true");
|
||||
settings.put(Environment.USE_SQL_COMMENTS, "true");
|
||||
settings.put(Environment.HBM2DDL_AUTO, "update");
|
||||
configuration.setProperties(settings);
|
||||
configuration.addAnnotatedClass(User.class);
|
||||
configuration.addAnnotatedClass(Address.class);
|
||||
configuration.addAnnotatedClass(Department.class);
|
||||
configuration.addAnnotatedClass(Employee.class);
|
||||
configuration.addAnnotatedClass(Book.class);
|
||||
configuration.addAnnotatedClass(Author.class);
|
||||
|
||||
|
||||
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
||||
.applySettings(configuration.getProperties()).build();
|
||||
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return sessionFactory;
|
||||
}
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
package com.baeldung.hibernate.exception.transientobject.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "address")
|
||||
public class Address {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private Long id;
|
||||
|
||||
@Column(name = "city")
|
||||
private String city;
|
||||
|
||||
@Column(name = "street")
|
||||
private String street;
|
||||
|
||||
@OneToOne(mappedBy = "address")
|
||||
private User user;
|
||||
|
||||
public Address() {
|
||||
}
|
||||
|
||||
public Address(String city, String street) {
|
||||
this.city = city;
|
||||
this.street = street;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public void setCity(String city) {
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public String getStreet() {
|
||||
return street;
|
||||
}
|
||||
|
||||
public void setStreet(String street) {
|
||||
this.street = street;
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
package com.baeldung.hibernate.exception.transientobject.entity;
|
||||
|
||||
import org.hibernate.annotations.Cascade;
|
||||
import org.hibernate.annotations.CascadeType;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@Entity
|
||||
@Table(name = "author")
|
||||
public class Author {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private int id;
|
||||
|
||||
@Column(name = "name")
|
||||
private String name;
|
||||
|
||||
@ManyToMany
|
||||
@Cascade({ CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.PERSIST})
|
||||
@JoinColumn(name = "book_id")
|
||||
private Set<Book> books = new HashSet<>();
|
||||
|
||||
public void addBook(Book book) {
|
||||
books.add(book);
|
||||
}
|
||||
|
||||
// standard getters and setters
|
||||
|
||||
public Author() {
|
||||
}
|
||||
|
||||
public Author(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Set<Book> getBooks() {
|
||||
return books;
|
||||
}
|
||||
|
||||
public void setBooks(Set<Book> books) {
|
||||
this.books = books;
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
package com.baeldung.hibernate.exception.transientobject.entity;
|
||||
|
||||
|
||||
import org.hibernate.annotations.Cascade;
|
||||
import org.hibernate.annotations.CascadeType;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@Entity
|
||||
@Table(name = "book")
|
||||
public class Book {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private int id;
|
||||
|
||||
@Column(name = "title")
|
||||
private String title;
|
||||
|
||||
@ManyToMany
|
||||
@Cascade({ CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.PERSIST})
|
||||
@JoinColumn(name = "author_id")
|
||||
private Set<Author> authors = new HashSet<>();
|
||||
|
||||
public void addAuthor(Author author) {
|
||||
authors.add(author);
|
||||
}
|
||||
|
||||
// standard getters and setters
|
||||
|
||||
public Book() {
|
||||
}
|
||||
|
||||
public Book(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public Set<Author> getAuthors() {
|
||||
return authors;
|
||||
}
|
||||
|
||||
public void setAuthors(Set<Author> authors) {
|
||||
this.authors = authors;
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
package com.baeldung.hibernate.exception.transientobject.entity;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@Entity
|
||||
@Table(name = "department")
|
||||
public class Department {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private int id;
|
||||
|
||||
@Column(name = "name")
|
||||
private String name;
|
||||
|
||||
@OneToMany(mappedBy = "department", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
private Set<Employee> employees = new HashSet<>();
|
||||
|
||||
public void addEmployee(Employee employee) {
|
||||
employees.add(employee);
|
||||
}
|
||||
|
||||
// standard getters and setters
|
||||
|
||||
public Department() {
|
||||
}
|
||||
|
||||
public Department(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Department(int id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Set<Employee> getEmployees() {
|
||||
return employees;
|
||||
}
|
||||
|
||||
public void setEmployees(Set<Employee> employees) {
|
||||
this.employees = employees;
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
package com.baeldung.hibernate.exception.transientobject.entity;
|
||||
|
||||
|
||||
import org.hibernate.annotations.Cascade;
|
||||
import org.hibernate.annotations.CascadeType;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "employee")
|
||||
public class Employee {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private int id;
|
||||
|
||||
@Column(name = "name")
|
||||
private String name;
|
||||
|
||||
@ManyToOne
|
||||
@Cascade(CascadeType.SAVE_UPDATE)
|
||||
@JoinColumn(name = "department_id")
|
||||
private Department department;
|
||||
|
||||
// standard getters and setters
|
||||
|
||||
public Employee() {
|
||||
}
|
||||
|
||||
public Employee(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Department getDepartment() {
|
||||
return department;
|
||||
}
|
||||
|
||||
public void setDepartment(Department department) {
|
||||
this.department = department;
|
||||
}
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
package com.baeldung.hibernate.exception.transientobject.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "user")
|
||||
public class User {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private int id;
|
||||
|
||||
@Column(name = "first_name")
|
||||
private String firstName;
|
||||
|
||||
@Column(name = "last_name")
|
||||
private String lastName;
|
||||
|
||||
@OneToOne(cascade = CascadeType.ALL)
|
||||
@JoinColumn(name = "address_id", referencedColumnName = "id")
|
||||
private Address address;
|
||||
|
||||
public User() {
|
||||
}
|
||||
|
||||
public User(String firstName, String lastName) {
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public Address getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(Address address) {
|
||||
this.address = address;
|
||||
}
|
||||
}
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
package com.baeldung.hibernate.exception.transientobject;
|
||||
|
||||
import com.baeldung.hibernate.exception.transientobject.entity.Address;
|
||||
import com.baeldung.hibernate.exception.transientobject.entity.Department;
|
||||
import com.baeldung.hibernate.exception.transientobject.entity.Author;
|
||||
import com.baeldung.hibernate.exception.transientobject.entity.Book;
|
||||
import com.baeldung.hibernate.exception.transientobject.entity.Employee;
|
||||
import com.baeldung.hibernate.exception.transientobject.entity.User;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
public class HibernateTransientObjectUnitTest {
|
||||
|
||||
private static SessionFactory sessionFactory;
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@BeforeClass
|
||||
public static void init() {
|
||||
sessionFactory = HibernateUtil.getSessionFactory();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSaveEntitiesWithOneToOneAssociation_thenSuccess() {
|
||||
User user = new User("Bob", "Smith");
|
||||
Address address = new Address("London", "221b Baker Street");
|
||||
user.setAddress(address);
|
||||
Session session = sessionFactory.openSession();
|
||||
session.beginTransaction();
|
||||
session.save(user);
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSaveEntitiesWithOneToManyAssociation_thenSuccess() {
|
||||
Department department = new Department();
|
||||
department.setName("IT Support");
|
||||
Employee employee = new Employee("John Doe");
|
||||
employee.setDepartment(department);
|
||||
Session session = sessionFactory.openSession();
|
||||
session.beginTransaction();
|
||||
session.save(employee);
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSaveEntitiesWithManyToManyAssociation_thenSuccess_1() {
|
||||
Book book = new Book("Design Patterns: Elements of Reusable Object-Oriented Software");
|
||||
book.addAuthor(new Author("Erich Gamma"));
|
||||
book.addAuthor(new Author("John Vlissides"));
|
||||
book.addAuthor(new Author("Richard Helm"));
|
||||
book.addAuthor(new Author("Ralph Johnson"));
|
||||
Session session = sessionFactory.openSession();
|
||||
session.beginTransaction();
|
||||
session.save(book);
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSaveEntitiesWithManyToManyAssociation_thenSuccess_2() {
|
||||
Author author = new Author("Erich Gamma");
|
||||
author.addBook(new Book("Design Patterns: Elements of Reusable Object-Oriented Software"));
|
||||
author.addBook(new Book("Introduction to Object Orient Design in C"));
|
||||
Session session = sessionFactory.openSession();
|
||||
session.beginTransaction();
|
||||
session.save(author);
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanUp() {
|
||||
sessionFactory.close();
|
||||
}
|
||||
}
|
||||
@@ -77,7 +77,7 @@
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${slf4j.version}</version>
|
||||
<version>${org.slf4j.version}</version>
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
@@ -174,12 +174,10 @@
|
||||
<javassist.version>3.27.0-GA</javassist.version>
|
||||
<jaxb.version>2.3.1</jaxb.version>
|
||||
<log4jdbc.version>2.0.0</log4jdbc.version>
|
||||
<logback.version>1.2.3</logback.version>
|
||||
<maven-jar-plugin.version>3.0.2</maven-jar-plugin.version>
|
||||
<maven.compiler.version>3.8.1</maven.compiler.version>
|
||||
<maven.version>3.8.1</maven.version>
|
||||
<mysql.version>8.0.19</mysql.version>
|
||||
<slf4j.version>1.7.30</slf4j.version>
|
||||
<spring-boot.version>2.1.3.RELEASE</spring-boot.version>
|
||||
</properties>
|
||||
|
||||
|
||||
@@ -14,3 +14,4 @@ This module contains articles about the Java Persistence API (JPA) in Java.
|
||||
- [How to Return Multiple Entities In JPA Query](https://www.baeldung.com/jpa-return-multiple-entities)
|
||||
- [Defining Unique Constraints in JPA](https://www.baeldung.com/jpa-unique-constraints)
|
||||
- [How to Check Field Existence in MongoDB?](https://www.baeldung.com/mongodb-check-field-exists)
|
||||
- [Connecting to a Specific Schema in JDBC](https://www.baeldung.com/jdbc-connect-to-schema)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>java-mongodb</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0"?>
|
||||
<project
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>redis</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
|
||||
@@ -146,7 +146,7 @@
|
||||
<jdbi.version>3.9.1</jdbi.version>
|
||||
<spring.boot.dependencies>2.1.8.RELEASE</spring.boot.dependencies>
|
||||
<c3p0.version>0.9.5.2</c3p0.version>
|
||||
<oracle-database.version>19.6.0.0</oracle-database.version>
|
||||
<oracle-database.version>21.1.0.0</oracle-database.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
+2
-1
@@ -20,7 +20,8 @@ public class OracleConfiguration {
|
||||
dataSource.setUser("books");
|
||||
dataSource.setPassword("books");
|
||||
dataSource.setURL("jdbc:oracle:thin:@//localhost:11521/ORCLPDB1");
|
||||
dataSource.setFastConnectionFailoverEnabled(true);
|
||||
// Only with clients prior to v21
|
||||
// dataSource.setFastConnectionFailoverEnabled(true);
|
||||
dataSource.setImplicitCachingEnabled(true);
|
||||
// Only with clients prior to v11.2
|
||||
// dataSource.setConnectionCachingEnabled(true);
|
||||
|
||||
-32
@@ -1,32 +0,0 @@
|
||||
package com.baeldung.spring.oracle.pooling.configuration;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
|
||||
import oracle.ucp.jdbc.PoolDataSource;
|
||||
import oracle.ucp.jdbc.PoolDataSourceFactory;
|
||||
|
||||
@Configuration
|
||||
@Profile("oracle-ucp")
|
||||
public class OracleUCPConfiguration {
|
||||
|
||||
@Bean
|
||||
public DataSource dataSource() throws SQLException {
|
||||
PoolDataSource dataSource = PoolDataSourceFactory.getPoolDataSource();
|
||||
dataSource.setUser("books");
|
||||
dataSource.setPassword("books");
|
||||
dataSource.setConnectionFactoryClassName("oracle.jdbc.pool.OracleDataSource");
|
||||
dataSource.setURL("jdbc:oracle:thin:@//localhost:11521/ORCLPDB1");
|
||||
|
||||
dataSource.setFastConnectionFailoverEnabled(true);
|
||||
dataSource.setInitialPoolSize(5);
|
||||
dataSource.setMinPoolSize(5);
|
||||
dataSource.setMaxPoolSize(10);
|
||||
return dataSource;
|
||||
}
|
||||
}
|
||||
+9
@@ -21,6 +21,15 @@ spring.datasource.hikari.poolName=HikariPoolBooks
|
||||
spring.datasource.tomcat.maxActive=15
|
||||
spring.datasource.tomcat.minIdle=5
|
||||
|
||||
# UCP settings
|
||||
#Note: These properties require JDBC version 21.0.0.0
|
||||
spring.datasource.ucp.connection-factory-class-name=oracle.jdbc.pool.OracleDataSource
|
||||
spring.datasource.ucp.sql-for-validate-connection=select * from dual
|
||||
spring.datasource.ucp.connection-pool-name=UcpPoolBooks
|
||||
spring.datasource.ucp.initial-pool-size=5
|
||||
spring.datasource.ucp.min-pool-size=5
|
||||
spring.datasource.ucp.max-pool-size=10
|
||||
|
||||
# JPA settings
|
||||
spring.jpa.database-platform=org.hibernate.dialect.Oracle12cDialect
|
||||
spring.jpa.hibernate.use-new-id-generator-mappings=false
|
||||
|
||||
+4
-2
@@ -9,11 +9,13 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = {SpringOraclePoolingApplication.class})
|
||||
@ActiveProfiles({"oracle-pooling-basic", "oracle-ucp"})
|
||||
@ActiveProfiles({"oracle-pooling-basic"})
|
||||
@TestPropertySource(properties = "spring.datasource.type=oracle.ucp.jdbc.UCPDataSource")
|
||||
public class SpringOraclePoolingApplicationOracleUCPLiveTest {
|
||||
|
||||
@Autowired
|
||||
@@ -21,7 +23,7 @@ public class SpringOraclePoolingApplicationOracleUCPLiveTest {
|
||||
|
||||
@Test
|
||||
public void givenOracleUCPConfiguration_thenBuildsOraclePoolDataSource() {
|
||||
assertTrue(dataSource instanceof oracle.ucp.jdbc.PoolDataSource);
|
||||
assertTrue(dataSource instanceof oracle.ucp.jdbc.UCPDataSource);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
@@ -6,3 +6,5 @@ jdbc.pass=sa
|
||||
hibernate.dialect=org.hibernate.dialect.H2Dialect
|
||||
hibernate.show_sql=true
|
||||
hibernate.hbm2ddl.auto=create-drop
|
||||
|
||||
spring.jpa.defer-datasource-initialization=true
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>spring-data-arangodb</artifactId>
|
||||
<name>spring-data-arangodb</name>
|
||||
@@ -18,7 +18,6 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.arangodb</groupId>
|
||||
<artifactId>arangodb-spring-data</artifactId>
|
||||
|
||||
@@ -2,6 +2,10 @@ FROM arangodb:3.8.0
|
||||
|
||||
COPY init-session.js /docker-entrypoint-initdb.d/
|
||||
|
||||
COPY arangodb-setup.js /setup/
|
||||
|
||||
EXPOSE 8529
|
||||
|
||||
ENV ARANGO_ROOT_PASSWORD=password
|
||||
|
||||
RUN chmod a+x /setup/arangodb-setup.js
|
||||
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/arangosh --javascript.execute
|
||||
|
||||
print('creating database: baeldung-database & user: baeldung');
|
||||
db._createDatabase("baeldung-database", {}, [{ username: "baeldung", passwd: "password", active: true}]);
|
||||
@@ -3,3 +3,5 @@
|
||||
docker image build -t spring-data-arangodb:live-test .
|
||||
|
||||
docker run -p 8529:8529 -e ARANGO_ROOT_PASSWORD=password --name spring-data-arangodb-live-test spring-data-arangodb:live-test
|
||||
|
||||
docker exec spring-data-arangodb-live-test arangosh --server.password password --javascript.execute /setup/arangodb-setup.js
|
||||
+1
-1
@@ -13,7 +13,7 @@ public class ArangoDbConfiguration implements ArangoConfiguration {
|
||||
public ArangoDB.Builder arango() {
|
||||
return new ArangoDB.Builder()
|
||||
.host("127.0.0.1", 8529)
|
||||
.user("root")
|
||||
.user("baeldung")
|
||||
.password("password");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
arangodb.hosts=127.0.0.1:8529
|
||||
arangodb.user=root
|
||||
arangodb.user=baeldung
|
||||
arangodb.password=password
|
||||
+6
@@ -2,6 +2,7 @@ package com.baeldung.arangodb;
|
||||
|
||||
import com.baeldung.arangodb.model.Article;
|
||||
import com.baeldung.arangodb.repository.ArticleRepository;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
@@ -25,6 +26,11 @@ public class ArticleRepositoryLiveTest {
|
||||
@Autowired
|
||||
ArticleRepository articleRepository;
|
||||
|
||||
@AfterEach
|
||||
public void tearDown(){
|
||||
articleRepository.deleteAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenNewArticle_whenSaveInArangoDb_thenDataIsCorrect() {
|
||||
Article newArticle = new Article(
|
||||
|
||||
@@ -28,6 +28,10 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
@@ -52,8 +56,7 @@
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<spring-boot.version>2.2.6.RELEASE</spring-boot.version>
|
||||
<cassandra-unit-spring.version>3.11.2.0</cassandra-unit-spring.version>
|
||||
<cassandra-unit-spring.version>4.3.1.0</cassandra-unit-spring.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
+2
-1
@@ -1,2 +1,3 @@
|
||||
spring.data.cassandra.keyspace-name=practice
|
||||
spring.data.cassandra.port=9042
|
||||
spring.data.cassandra.port=9042
|
||||
spring.data.cassandra.local-datacenter=datacenter1
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>spring-data-cassandra-test</artifactId>
|
||||
<name>spring-data-cassandra-test</name>
|
||||
@@ -14,6 +14,50 @@
|
||||
<relativePath>../../parent-boot-2</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-cassandra</artifactId>
|
||||
<version>${spring-boot-starter-data-cassandra.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.datastax.oss</groupId>
|
||||
<artifactId>java-driver-core</artifactId>
|
||||
<version>${java-driver-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.datastax.oss</groupId>
|
||||
<artifactId>native-protocol</artifactId>
|
||||
<version>${native-protocol.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>testcontainers</artifactId>
|
||||
<version>${testcontainers.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>cassandra</artifactId>
|
||||
<version>${testcontainers.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<spring-boot-starter-data-cassandra.version>2.5.3</spring-boot-starter-data-cassandra.version>
|
||||
<lombok.version>1.18.18</lombok.version>
|
||||
@@ -23,55 +67,4 @@
|
||||
<native-protocol.version>1.5.0</native-protocol.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-cassandra</artifactId>
|
||||
<version>${spring-boot-starter-data-cassandra.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.datastax.oss</groupId>
|
||||
<artifactId>java-driver-core</artifactId>
|
||||
<version>${java-driver-core.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.datastax.oss</groupId>
|
||||
<artifactId>native-protocol</artifactId>
|
||||
<version>${native-protocol.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>testcontainers</artifactId>
|
||||
<version>${testcontainers.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>cassandra</artifactId>
|
||||
<version>${testcontainers.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -1,8 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
|
||||
http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>spring-data-jpa-crud</artifactId>
|
||||
<name>spring-data-jpa-crud</name>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
spring.jpa.properties.hibernate.jdbc.batch_size=4
|
||||
spring.jpa.properties.hibernate.order_inserts=true
|
||||
spring.jpa.properties.hibernate.order_updates=true
|
||||
spring.jpa.properties.hibernate.generate_statistics=true
|
||||
|
||||
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
|
||||
|
||||
|
||||
+4
-2
@@ -9,6 +9,7 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
@@ -20,6 +21,7 @@ import com.baeldung.boot.web.controllers.CustomerController;
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes=Application.class)
|
||||
@AutoConfigureMockMvc
|
||||
@ActiveProfiles("stats")
|
||||
public class BatchInsertIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
@@ -35,6 +37,6 @@ public class BatchInsertIntegrationTest {
|
||||
public void whenInsertingCustomers_thenCustomersAreCreated() throws Exception {
|
||||
this.mockMvc.perform(post("/customers"))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+3
-1
@@ -3,4 +3,6 @@ spring.jpa.show-sql=false
|
||||
spring.jpa.properties.hibernate.jdbc.batch_size=5
|
||||
spring.jpa.properties.hibernate.order_inserts=true
|
||||
spring.jpa.properties.hibernate.order_updates=true
|
||||
spring.jpa.properties.hibernate.batch_versioned_data=true
|
||||
spring.jpa.properties.hibernate.batch_versioned_data=true
|
||||
|
||||
spring.jpa.properties.hibernate.generate_statistics=true
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
spring.jpa.properties.hibernate.jdbc.batch_size=4
|
||||
spring.jpa.properties.hibernate.order_inserts=true
|
||||
spring.jpa.properties.hibernate.order_updates=true
|
||||
|
||||
spring.jpa.properties.hibernate.generate_statistics=true
|
||||
+28
-1
@@ -3,20 +3,23 @@ package com.baeldung.boot.daos;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Optional;
|
||||
|
||||
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 org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.baeldung.Application;
|
||||
import com.baeldung.boot.domain.MerchandiseEntity;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes=Application.class)
|
||||
@SpringBootTest(classes = Application.class)
|
||||
public class InventoryRepositoryIntegrationTest {
|
||||
|
||||
private static final String ORIGINAL_TITLE = "Pair of Pants";
|
||||
@@ -58,4 +61,28 @@ public class InventoryRepositoryIntegrationTest {
|
||||
assertEquals(BigDecimal.TEN, result.getPrice());
|
||||
assertEquals(UPDATED_BRAND, result.getBrand());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void shouldUpdateExistingEntryInDBWithoutSave() {
|
||||
MerchandiseEntity pants = new MerchandiseEntity(ORIGINAL_TITLE, BigDecimal.ONE);
|
||||
pants = repository.save(pants);
|
||||
|
||||
Long originalId = pants.getId();
|
||||
|
||||
// Update using setters
|
||||
pants.setTitle(UPDATED_TITLE);
|
||||
pants.setPrice(BigDecimal.TEN);
|
||||
pants.setBrand(UPDATED_BRAND);
|
||||
|
||||
Optional<MerchandiseEntity> resultOp = repository.findById(originalId);
|
||||
|
||||
assertTrue(resultOp.isPresent());
|
||||
MerchandiseEntity result = resultOp.get();
|
||||
|
||||
assertEquals(originalId, result.getId());
|
||||
assertEquals(UPDATED_TITLE, result.getTitle());
|
||||
assertEquals(BigDecimal.TEN, result.getPrice());
|
||||
assertEquals(UPDATED_BRAND, result.getBrand());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,4 +7,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||
|
||||
### Relevant Articles
|
||||
- [Spring Data Reactive Repositories with MongoDB](https://www.baeldung.com/spring-data-mongodb-reactive)
|
||||
- [Spring Data MongoDB Tailable Cursors](https://www.baeldung.com/spring-data-mongodb-tailable-cursors)
|
||||
- [Spring Data MongoDB Tailable Cursors](https://www.baeldung.com/spring-data-mongodb-tailable-cursors)
|
||||
Reference in New Issue
Block a user