JAVA-30208: Changes made for adding spring-hibernate-5 (#15659)

This commit is contained in:
Bipin kumar 2024-01-31 20:13:41 +05:30 committed by GitHub
parent faaf189afb
commit 4bde015e08
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 71 additions and 37 deletions

View File

@ -102,7 +102,7 @@
<module>spring-data-solr</module>
<module>spring-data-shardingsphere</module>
<module>spring-hibernate-3</module>
<!-- <module>spring-hibernate-5</module> FAILED --> <!-- long running -->
<module>spring-hibernate-5</module>
<module>spring-hibernate-6</module>
<module>spring-jpa</module>
<module>spring-jpa-2</module>

View File

@ -125,6 +125,20 @@
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>
--add-opens java.base/java.lang=ALL-UNNAMED
</argLine>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<!-- Spring -->
<org.springframework.version>5.0.2.RELEASE</org.springframework.version>
@ -132,7 +146,7 @@
<org.springframework.security.version>4.2.1.RELEASE</org.springframework.security.version>
<!-- persistence -->
<hibernate.version>5.6.15.Final</hibernate.version>
<hibernatesearch.version>5.8.2.Final</hibernatesearch.version>
<hibernatesearch.version>5.11.12.Final</hibernatesearch.version>
<mysql-connector-java.version>8.2.0</mysql-connector-java.version>
<tomcat-dbcp.version>9.0.0.M26</tomcat-dbcp.version>
<jta.version>1.1</jta.version>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true"
monitoring="autodetect" dynamicConfig="true">
<diskStore path="java.io.tmpdir/ehcache" />
<defaultCache maxEntriesLocalHeap="10000" eternal="false"
timeToIdleSeconds="120" timeToLiveSeconds="120" diskSpoolBufferSizeMB="30"
maxEntriesLocalDisk="10000000" diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU" statistics="true">
<persistence strategy="localTempSwap" />
</defaultCache>
<cache name="org.hibernate.cache.internal.StandardQueryCache"
maxEntriesLocalHeap="5" eternal="false" timeToLiveSeconds="120">
<persistence strategy="localTempSwap" />
</cache>
</ehcache>

View File

@ -7,13 +7,13 @@ import javax.persistence.*;
@Entity
@Table(name = "FOO")
@Where(clause = "DELETED = 0")
public class Foo {
public class Fooo {
public Foo() {
public Fooo() {
super();
}
public Foo(final String name) {
public Fooo(final String name) {
super();
this.name = name;
}

View File

@ -14,7 +14,7 @@ import org.springframework.transaction.annotation.Transactional;
import com.baeldung.persistence.deletion.config.PersistenceJPAConfigDeletion;
import com.baeldung.persistence.deletion.model.Bar;
import com.baeldung.persistence.deletion.model.Baz;
import com.baeldung.persistence.deletion.model.Foo;
import com.baeldung.persistence.deletion.model.Fooo;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@ -41,29 +41,29 @@ public class DeletionIntegrationTest {
@Test
@Transactional
public final void givenEntityIsRemoved_thenItIsNotInDB() {
Foo foo = new Foo("foo");
entityManager.persist(foo);
Fooo fooo = new Fooo("foo");
entityManager.persist(fooo);
flushAndClear();
foo = entityManager.find(Foo.class, foo.getId());
assertThat(foo, notNullValue());
fooo = entityManager.find(Fooo.class, fooo.getId());
assertThat(fooo, notNullValue());
entityManager.remove(foo);
entityManager.remove(fooo);
flushAndClear();
assertThat(entityManager.find(Foo.class, foo.getId()), nullValue());
assertThat(entityManager.find(Fooo.class, fooo.getId()), nullValue());
}
@Test
@Transactional
public final void givenEntityIsRemovedAndReferencedByAnotherEntity_thenItIsNotRemoved() {
Bar bar = new Bar("bar");
Foo foo = new Foo("foo");
foo.setBar(bar);
entityManager.persist(foo);
Fooo fooo = new Fooo("foo");
fooo.setBar(bar);
entityManager.persist(fooo);
flushAndClear();
foo = entityManager.find(Foo.class, foo.getId());
fooo = entityManager.find(Fooo.class, fooo.getId());
bar = entityManager.find(Bar.class, bar.getId());
entityManager.remove(bar);
flushAndClear();
@ -71,8 +71,8 @@ public class DeletionIntegrationTest {
bar = entityManager.find(Bar.class, bar.getId());
assertThat(bar, notNullValue());
foo = entityManager.find(Foo.class, foo.getId());
foo.setBar(null);
fooo = entityManager.find(Fooo.class, fooo.getId());
fooo.setBar(null);
entityManager.remove(bar);
flushAndClear();
@ -83,16 +83,16 @@ public class DeletionIntegrationTest {
@Transactional
public final void givenEntityIsRemoved_thenRemovalIsCascaded() {
Bar bar = new Bar("bar");
Foo foo = new Foo("foo");
foo.setBar(bar);
entityManager.persist(foo);
Fooo fooo = new Fooo("foo");
fooo.setBar(bar);
entityManager.persist(fooo);
flushAndClear();
foo = entityManager.find(Foo.class, foo.getId());
entityManager.remove(foo);
fooo = entityManager.find(Fooo.class, fooo.getId());
entityManager.remove(fooo);
flushAndClear();
assertThat(entityManager.find(Foo.class, foo.getId()), nullValue());
assertThat(entityManager.find(Fooo.class, fooo.getId()), nullValue());
assertThat(entityManager.find(Bar.class, bar.getId()), nullValue());
}
@ -116,39 +116,39 @@ public class DeletionIntegrationTest {
@Test
@Transactional
public final void givenEntityIsDeletedWithJpaBulkDeleteStatement_thenItIsNotInDB() {
Foo foo = new Foo("foo");
entityManager.persist(foo);
Fooo fooo = new Fooo("foo");
entityManager.persist(fooo);
flushAndClear();
entityManager.createQuery("delete from Foo where id = :id").setParameter("id", foo.getId()).executeUpdate();
entityManager.createQuery("delete from Foo where id = :id").setParameter("id", fooo.getId()).executeUpdate();
assertThat(entityManager.find(Foo.class, foo.getId()), nullValue());
assertThat(entityManager.find(Fooo.class, fooo.getId()), nullValue());
}
@Test
@Transactional
public final void givenEntityIsDeletedWithNativeQuery_thenItIsNotInDB() {
Foo foo = new Foo("foo");
entityManager.persist(foo);
Fooo fooo = new Fooo("foo");
entityManager.persist(fooo);
flushAndClear();
entityManager.createNativeQuery("delete from FOO where ID = :id").setParameter("id", foo.getId()).executeUpdate();
entityManager.createNativeQuery("delete from FOO where ID = :id").setParameter("id", fooo.getId()).executeUpdate();
assertThat(entityManager.find(Foo.class, foo.getId()), nullValue());
assertThat(entityManager.find(Fooo.class, fooo.getId()), nullValue());
}
@Test
@Transactional
public final void givenEntityIsSoftDeleted_thenItIsNotReturnedFromQueries() {
Foo foo = new Foo("foo");
entityManager.persist(foo);
Fooo fooo = new Fooo("foo");
entityManager.persist(fooo);
flushAndClear();
foo = entityManager.find(Foo.class, foo.getId());
foo.setDeleted();
fooo = entityManager.find(Fooo.class, fooo.getId());
fooo.setDeleted();
flushAndClear();
assertThat(entityManager.find(Foo.class, foo.getId()), nullValue());
assertThat(entityManager.find(Fooo.class, fooo.getId()), nullValue());
}
private void flushAndClear() {