[JAVA-31185] - Upgrade to Hibernate latest version for persistence modules (#15832)
This commit is contained in:
parent
5b86742881
commit
a246045b48
|
@ -18,6 +18,12 @@
|
||||||
<artifactId>transactions-jdbc</artifactId>
|
<artifactId>transactions-jdbc</artifactId>
|
||||||
<version>${atomikos-version}</version>
|
<version>${atomikos-version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.atomikos</groupId>
|
||||||
|
<artifactId>transactions-jta</artifactId>
|
||||||
|
<version>${atomikos-version}</version>
|
||||||
|
<classifier>jakarta</classifier>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.atomikos</groupId>
|
<groupId>com.atomikos</groupId>
|
||||||
<artifactId>transactions-jms</artifactId>
|
<artifactId>transactions-jms</artifactId>
|
||||||
|
@ -90,10 +96,10 @@
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<atomikos-version>5.0.6</atomikos-version>
|
<atomikos-version>6.0.0</atomikos-version>
|
||||||
<spring-version>5.1.6.RELEASE</spring-version>
|
<spring-version>6.1.2</spring-version>
|
||||||
<hibernate.version>5.4.3.Final</hibernate.version>
|
<hibernate.version>6.4.2.Final</hibernate.version>
|
||||||
<spring-data-jpa.version>1.11.23.RELEASE</spring-data-jpa.version>
|
<spring-data-jpa.version>3.2.2</spring-data-jpa.version>
|
||||||
<activemq-core.version>5.7.0</activemq-core.version>
|
<activemq-core.version>5.7.0</activemq-core.version>
|
||||||
<derby.version>10.8.1.2</derby.version>
|
<derby.version>10.8.1.2</derby.version>
|
||||||
<jta.version>1.1</jta.version>
|
<jta.version>1.1</jta.version>
|
||||||
|
|
|
@ -1,17 +1,14 @@
|
||||||
package com.baeldung.atomikos.spring.config;
|
package com.baeldung.atomikos.spring.config;
|
||||||
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import javax.transaction.SystemException;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
|
||||||
import org.springframework.transaction.jta.JtaTransactionManager;
|
|
||||||
|
|
||||||
import com.atomikos.icatch.jta.UserTransactionManager;
|
import com.atomikos.icatch.jta.UserTransactionManager;
|
||||||
import com.atomikos.jdbc.AtomikosDataSourceBean;
|
import com.atomikos.jdbc.AtomikosDataSourceBean;
|
||||||
import com.baeldung.atomikos.spring.Application;
|
import com.baeldung.atomikos.spring.Application;
|
||||||
|
import jakarta.transaction.SystemException;
|
||||||
|
import java.util.Properties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
import org.springframework.transaction.jta.JtaTransactionManager;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableTransactionManagement
|
@EnableTransactionManagement
|
||||||
|
@ -46,7 +43,7 @@ public class Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean(initMethod = "init", destroyMethod = "close")
|
@Bean(initMethod = "init", destroyMethod = "close")
|
||||||
public UserTransactionManager userTransactionManager() throws SystemException {
|
public UserTransactionManager userTransactionManager() throws jakarta.transaction.SystemException {
|
||||||
UserTransactionManager userTransactionManager = new UserTransactionManager();
|
UserTransactionManager userTransactionManager = new UserTransactionManager();
|
||||||
userTransactionManager.setTransactionTimeout(300);
|
userTransactionManager.setTransactionTimeout(300);
|
||||||
userTransactionManager.setForceShutdown(true);
|
userTransactionManager.setForceShutdown(true);
|
||||||
|
|
|
@ -29,13 +29,13 @@ public class Application {
|
||||||
|
|
||||||
String orderId = UUID.randomUUID()
|
String orderId = UUID.randomUUID()
|
||||||
.toString();
|
.toString();
|
||||||
Inventory inventory = inventoryRepository.findOne(productId);
|
Inventory inventory = inventoryRepository.getReferenceById(productId);
|
||||||
inventory.setBalance(inventory.getBalance() - amount);
|
inventory.setBalance(inventory.getBalance() - amount);
|
||||||
inventoryRepository.save(inventory);
|
inventoryRepository.save(inventory);
|
||||||
Order order = new Order();
|
Order order = new Order();
|
||||||
order.setOrderId(orderId);
|
order.setOrderId(orderId);
|
||||||
order.setProductId(productId);
|
order.setProductId(productId);
|
||||||
order.setAmount(new Long(amount));
|
order.setAmount( Long.valueOf(amount));
|
||||||
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
|
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
|
||||||
Validator validator = factory.getValidator();
|
Validator validator = factory.getValidator();
|
||||||
Set<ConstraintViolation<Order>> violations = validator.validate(order);
|
Set<ConstraintViolation<Order>> violations = validator.validate(order);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.baeldung.atomikos.spring.jpa.config;
|
package com.baeldung.atomikos.spring.jpa.config;
|
||||||
|
|
||||||
import javax.transaction.SystemException;
|
import jakarta.transaction.SystemException;
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.baeldung.atomikos.spring.jpa.inventory;
|
package com.baeldung.atomikos.spring.jpa.inventory;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import javax.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import javax.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "INVENTORY")
|
@Table(name = "INVENTORY")
|
||||||
|
|
|
@ -2,7 +2,7 @@ package com.baeldung.atomikos.spring.jpa.inventory;
|
||||||
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import javax.persistence.EntityManagerFactory;
|
import jakarta.persistence.EntityManagerFactory;
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.baeldung.atomikos.spring.jpa.order;
|
package com.baeldung.atomikos.spring.jpa.order;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import javax.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import javax.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
import jakarta.validation.constraints.Max;
|
import jakarta.validation.constraints.Max;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
|
|
|
@ -2,7 +2,7 @@ package com.baeldung.atomikos.spring.jpa.order;
|
||||||
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import javax.persistence.EntityManagerFactory;
|
import jakarta.persistence.EntityManagerFactory;
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
|
@ -72,7 +72,7 @@ public class ApplicationUnitTest {
|
||||||
|
|
||||||
private static long getBalance(InventoryRepository inventoryRepository, String productId) throws Exception {
|
private static long getBalance(InventoryRepository inventoryRepository, String productId) throws Exception {
|
||||||
|
|
||||||
return inventoryRepository.findOne(productId)
|
return inventoryRepository.getReferenceById(productId)
|
||||||
.getBalance();
|
.getBalance();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hibernate</groupId>
|
<groupId>org.hibernate.orm</groupId>
|
||||||
<artifactId>hibernate-core</artifactId>
|
<artifactId>hibernate-core</artifactId>
|
||||||
<version>${hibernate.version}</version>
|
<version>${hibernate.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
@ -25,7 +25,7 @@
|
||||||
<version>${h2.version}</version>
|
<version>${h2.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hibernate</groupId>
|
<groupId>org.hibernate.orm</groupId>
|
||||||
<artifactId>hibernate-spatial</artifactId>
|
<artifactId>hibernate-spatial</artifactId>
|
||||||
<version>${hibernate.version}</version>
|
<version>${hibernate.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
@ -45,7 +45,7 @@
|
||||||
<version>${mariaDB4j.version}</version>
|
<version>${mariaDB4j.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hibernate</groupId>
|
<groupId>org.hibernate.orm</groupId>
|
||||||
<artifactId>hibernate-testing</artifactId>
|
<artifactId>hibernate-testing</artifactId>
|
||||||
<version>${hibernate.version}</version>
|
<version>${hibernate.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
@ -82,6 +82,7 @@
|
||||||
<mysql.version>8.2.0</mysql.version>
|
<mysql.version>8.2.0</mysql.version>
|
||||||
<mariaDB4j.version>2.6.0</mariaDB4j.version>
|
<mariaDB4j.version>2.6.0</mariaDB4j.version>
|
||||||
<geodb.version>0.9</geodb.version>
|
<geodb.version>0.9</geodb.version>
|
||||||
|
<hibernate.version>6.4.2.Final</hibernate.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -9,12 +9,16 @@ import java.util.List;
|
||||||
import jakarta.persistence.OptimisticLockException;
|
import jakarta.persistence.OptimisticLockException;
|
||||||
import jakarta.persistence.PersistenceException;
|
import jakarta.persistence.PersistenceException;
|
||||||
|
|
||||||
|
import org.h2.jdbc.JdbcSQLDataException;
|
||||||
|
import org.h2.jdbc.JdbcSQLIntegrityConstraintViolationException;
|
||||||
|
import org.h2.jdbc.JdbcSQLSyntaxErrorException;
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
import org.hibernate.NonUniqueObjectException;
|
import org.hibernate.NonUniqueObjectException;
|
||||||
import org.hibernate.PropertyValueException;
|
import org.hibernate.PropertyValueException;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
|
import org.hibernate.StaleObjectStateException;
|
||||||
import org.hibernate.StaleStateException;
|
import org.hibernate.StaleStateException;
|
||||||
import org.hibernate.Transaction;
|
import org.hibernate.Transaction;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
|
@ -132,8 +136,8 @@ public class HibernateExceptionUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenMissingTable_whenEntitySaved_thenSQLGrammarException() {
|
public void givenMissingTable_whenEntitySaved_thenSQLGrammarException() {
|
||||||
thrown.expectCause(isA(SQLGrammarException.class));
|
thrown.expectCause(isA(JdbcSQLSyntaxErrorException.class));
|
||||||
thrown.expectMessage("could not prepare statement");
|
thrown.expectMessage("Table \"PRODUCT\" not found (this database is empty); SQL statement");
|
||||||
|
|
||||||
Configuration cfg = getConfiguration();
|
Configuration cfg = getConfiguration();
|
||||||
cfg.addAnnotatedClass(Product.class);
|
cfg.addAnnotatedClass(Product.class);
|
||||||
|
@ -161,8 +165,8 @@ public class HibernateExceptionUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenMissingTable_whenQueryExecuted_thenSQLGrammarException() {
|
public void givenMissingTable_whenQueryExecuted_thenSQLGrammarException() {
|
||||||
thrown.expectCause(isA(SQLGrammarException.class));
|
thrown.expectCause(isA(JdbcSQLSyntaxErrorException.class));
|
||||||
thrown.expectMessage("could not prepare statement");
|
thrown.expectMessage("Table \"NON_EXISTING_TABLE\" not found");
|
||||||
|
|
||||||
Session session = sessionFactory.openSession();
|
Session session = sessionFactory.openSession();
|
||||||
NativeQuery<Product> query = session.createNativeQuery("select * from NON_EXISTING_TABLE", Product.class);
|
NativeQuery<Product> query = session.createNativeQuery("select * from NON_EXISTING_TABLE", Product.class);
|
||||||
|
@ -171,7 +175,7 @@ public class HibernateExceptionUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenDuplicateIdSaved_thenConstraintViolationException() {
|
public void whenDuplicateIdSaved_thenConstraintViolationException() {
|
||||||
thrown.expectCause(isA(ConstraintViolationException.class));
|
thrown.expectCause(isA(JdbcSQLIntegrityConstraintViolationException.class));
|
||||||
thrown.expectMessage("could not execute statement");
|
thrown.expectMessage("could not execute statement");
|
||||||
|
|
||||||
Session session = null;
|
Session session = null;
|
||||||
|
@ -224,7 +228,7 @@ public class HibernateExceptionUnitTest {
|
||||||
public void givenEntityWithoutId_whenCallingSave_thenThrowIdentifierGenerationException() {
|
public void givenEntityWithoutId_whenCallingSave_thenThrowIdentifierGenerationException() {
|
||||||
|
|
||||||
thrown.expect(isA(IdentifierGenerationException.class));
|
thrown.expect(isA(IdentifierGenerationException.class));
|
||||||
thrown.expectMessage("ids for this class must be manually assigned before calling save(): com.baeldung.hibernate.exception.Product");
|
thrown.expectMessage("Identifier of entity 'com.baeldung.hibernate.exception.ProductEntity' must be manually assigned before calling 'persist()");
|
||||||
|
|
||||||
Session session = null;
|
Session session = null;
|
||||||
Transaction transaction = null;
|
Transaction transaction = null;
|
||||||
|
@ -249,8 +253,8 @@ public class HibernateExceptionUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenQueryWithDataTypeMismatch_WhenQueryExecuted_thenDataException() {
|
public void givenQueryWithDataTypeMismatch_WhenQueryExecuted_thenDataException() {
|
||||||
thrown.expectCause(isA(DataException.class));
|
thrown.expectCause(isA(JdbcSQLDataException.class));
|
||||||
thrown.expectMessage("could not prepare statement");
|
thrown.expectMessage("Data conversion error converting \"wrongTypeId\"");
|
||||||
|
|
||||||
Session session = sessionFactory.openSession();
|
Session session = sessionFactory.openSession();
|
||||||
NativeQuery<Product> query = session.createNativeQuery("select * from PRODUCT where id='wrongTypeId'", Product.class);
|
NativeQuery<Product> query = session.createNativeQuery("select * from PRODUCT where id='wrongTypeId'", Product.class);
|
||||||
|
@ -291,7 +295,7 @@ public class HibernateExceptionUnitTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenDeletingADeletedObject_thenOptimisticLockException() {
|
public void whenDeletingADeletedObject_thenOptimisticLockException() {
|
||||||
thrown.expect(isA(OptimisticLockException.class));
|
thrown.expect(isA(OptimisticLockException.class));
|
||||||
thrown.expectMessage("Batch update returned unexpected row count from update");
|
thrown.expectMessage("Row was updated or deleted by another transaction");
|
||||||
thrown.expectCause(isA(StaleStateException.class));
|
thrown.expectCause(isA(StaleStateException.class));
|
||||||
|
|
||||||
Session session = null;
|
Session session = null;
|
||||||
|
@ -327,8 +331,8 @@ public class HibernateExceptionUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenUpdatingNonExistingObject_thenStaleStateException() {
|
public void whenUpdatingNonExistingObject_thenStaleStateException() {
|
||||||
thrown.expectCause(isA(StaleStateException.class));
|
thrown.expectCause(isA(StaleObjectStateException.class));
|
||||||
thrown.expectMessage("Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1; statement executed: update PRODUCT set description=?, name=? where id=?");
|
thrown.expectMessage("Row was updated or deleted by another transaction");
|
||||||
|
|
||||||
Session session = null;
|
Session session = null;
|
||||||
Transaction transaction = null;
|
Transaction transaction = null;
|
||||||
|
@ -409,9 +413,7 @@ public class HibernateExceptionUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenExistingEntity_whenIdUpdated_thenHibernateException() {
|
public void givenExistingEntity_whenIdUpdated_thenHibernateException() {
|
||||||
thrown.expect(isA(PersistenceException.class));
|
thrown.expect(isA(HibernateException.class));
|
||||||
thrown.expectCause(isA(HibernateException.class));
|
|
||||||
thrown.expectMessage("identifier of an instance of com.baeldung.hibernate.exception.Product was altered");
|
|
||||||
|
|
||||||
Session session = null;
|
Session session = null;
|
||||||
Transaction transaction = null;
|
Transaction transaction = null;
|
||||||
|
|
|
@ -10,7 +10,7 @@ import org.hibernate.engine.jdbc.connections.spi.AbstractMultiTenantConnectionPr
|
||||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class MapMultiTenantConnectionProvider extends AbstractMultiTenantConnectionProvider {
|
public class MapMultiTenantConnectionProvider extends AbstractMultiTenantConnectionProvider<String> {
|
||||||
|
|
||||||
private final Map<String, ConnectionProvider> connectionProviderMap = new HashMap<>();
|
private final Map<String, ConnectionProvider> connectionProviderMap = new HashMap<>();
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ public class MapMultiTenantConnectionProvider extends AbstractMultiTenantConnect
|
||||||
.next();
|
.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ConnectionProvider selectConnectionProvider(String tenantIdentifier) {
|
protected ConnectionProvider selectConnectionProvider(String tenantIdentifier) {
|
||||||
return connectionProviderMap.get(tenantIdentifier);
|
return connectionProviderMap.get(tenantIdentifier);
|
||||||
|
|
|
@ -12,7 +12,7 @@ import org.hibernate.engine.jdbc.connections.spi.AbstractMultiTenantConnectionPr
|
||||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class SchemaMultiTenantConnectionProvider extends AbstractMultiTenantConnectionProvider {
|
public class SchemaMultiTenantConnectionProvider extends AbstractMultiTenantConnectionProvider<String> {
|
||||||
|
|
||||||
private final ConnectionProvider connectionProvider;
|
private final ConnectionProvider connectionProvider;
|
||||||
|
|
||||||
|
|
|
@ -179,7 +179,7 @@ public class SaveMethodsIntegrationTest {
|
||||||
.commit();
|
.commit();
|
||||||
session.beginTransaction();
|
session.beginTransaction();
|
||||||
|
|
||||||
assertNull(person.getId());
|
assertNotNull(person.getId());
|
||||||
assertNotNull(mergedPerson.getId());
|
assertNotNull(mergedPerson.getId());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
<version>${hsqldb.version}</version>
|
<version>${hsqldb.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hibernate</groupId>
|
<groupId>org.hibernate.orm</groupId>
|
||||||
<artifactId>hibernate-core</artifactId>
|
<artifactId>hibernate-core</artifactId>
|
||||||
<version>${hibernate.version}</version>
|
<version>${hibernate.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
@ -34,6 +34,7 @@
|
||||||
<properties>
|
<properties>
|
||||||
<hsqldb.version>2.7.1</hsqldb.version>
|
<hsqldb.version>2.7.1</hsqldb.version>
|
||||||
<h2.version>2.1.214</h2.version>
|
<h2.version>2.1.214</h2.version>
|
||||||
|
<hibernate.version>6.4.2.Final</hibernate.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -26,9 +26,8 @@ public class Author {
|
||||||
@Column(name = "name")
|
@Column(name = "name")
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@ManyToMany
|
|
||||||
@Cascade({ CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.PERSIST})
|
@Cascade({ CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.PERSIST})
|
||||||
@JoinColumn(name = "book_id")
|
@ManyToMany(mappedBy = "authors")
|
||||||
private Set<Book> books = new HashSet<>();
|
private Set<Book> books = new HashSet<>();
|
||||||
|
|
||||||
public void addBook(Book book) {
|
public void addBook(Book book) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.baeldung.hibernate.exception.transientobject.entity;
|
package com.baeldung.hibernate.exception.transientobject.entity;
|
||||||
|
|
||||||
|
|
||||||
|
import jakarta.persistence.JoinTable;
|
||||||
import org.hibernate.annotations.Cascade;
|
import org.hibernate.annotations.Cascade;
|
||||||
import org.hibernate.annotations.CascadeType;
|
import org.hibernate.annotations.CascadeType;
|
||||||
|
|
||||||
|
@ -29,7 +30,7 @@ public class Book {
|
||||||
|
|
||||||
@ManyToMany
|
@ManyToMany
|
||||||
@Cascade({ CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.PERSIST})
|
@Cascade({ CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.PERSIST})
|
||||||
@JoinColumn(name = "author_id")
|
@JoinTable(joinColumns = { @JoinColumn(name = "author_id") })
|
||||||
private Set<Author> authors = new HashSet<>();
|
private Set<Author> authors = new HashSet<>();
|
||||||
|
|
||||||
public void addAuthor(Author author) {
|
public void addAuthor(Author author) {
|
||||||
|
|
|
@ -44,7 +44,7 @@ class NamedParameterNotBoundExceptionUnitTest {
|
||||||
query.list();
|
query.list();
|
||||||
});
|
});
|
||||||
|
|
||||||
String expectedMessage = "Named parameter not bound";
|
String expectedMessage = "No argument for named parameter";
|
||||||
String actualMessage = exception.getMessage();
|
String actualMessage = exception.getMessage();
|
||||||
|
|
||||||
assertTrue(actualMessage.contains(expectedMessage));
|
assertTrue(actualMessage.contains(expectedMessage));
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hibernate</groupId>
|
<groupId>org.hibernate.orm</groupId>
|
||||||
<artifactId>hibernate-core</artifactId>
|
<artifactId>hibernate-core</artifactId>
|
||||||
<version>${hibernate.version}</version>
|
<version>${hibernate.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
@ -84,6 +84,7 @@
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<mysql.version>8.2.0</mysql.version>
|
<mysql.version>8.2.0</mysql.version>
|
||||||
|
<hibernate.version>6.4.2.Final</hibernate.version>
|
||||||
<mariaDB4j.version>2.6.0</mariaDB4j.version>
|
<mariaDB4j.version>2.6.0</mariaDB4j.version>
|
||||||
<spring-boot.version>3.0.4</spring-boot.version>
|
<spring-boot.version>3.0.4</spring-boot.version>
|
||||||
<h2.version>2.1.214</h2.version>
|
<h2.version>2.1.214</h2.version>
|
||||||
|
|
Loading…
Reference in New Issue