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