Skip to content

Commit 0128734

Browse files
committed
Adjust tests
1 parent 5bab590 commit 0128734

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

core/src/test/java/com/vladmihalcea/book/hpjp/hibernate/association/BidirectionalOneToOneOptionalTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ public void testLifecycle() {
3535
LOGGER.info("Fetching Post");
3636
Post post = entityManager.find(Post.class, 1L);
3737
assertNotNull(post);
38-
39-
post.setDetails(null);
4038
});
4139
}
4240

@@ -50,7 +48,7 @@ public static class Post {
5048

5149
private String title;
5250

53-
@OneToOne(mappedBy = "post", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
51+
@OneToOne(mappedBy = "post", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true, optional = true)
5452
private PostDetails details;
5553

5654
public Post() {}
@@ -107,7 +105,7 @@ public static class PostDetails {
107105
private String createdBy;
108106

109107
@OneToOne(fetch = FetchType.LAZY)
110-
@JoinColumn(name = "post_id")
108+
@MapsId
111109
private Post post;
112110

113111
public PostDetails() {}

core/src/test/java/com/vladmihalcea/book/hpjp/hibernate/inheritance/TablePerClassTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.vladmihalcea.book.hpjp.hibernate.inheritance;
22

33
import com.vladmihalcea.book.hpjp.util.AbstractTest;
4+
import com.vladmihalcea.book.hpjp.util.providers.Database;
45
import org.junit.Test;
56

67
import javax.persistence.*;
@@ -26,6 +27,14 @@ protected Class<?>[] entities() {
2627
};
2728
}
2829

30+
@Override
31+
protected Database database() {
32+
// When using MySQL with older Hibernate versions,
33+
// UNION is used instead of UNION ALL
34+
// return Database.MYSQL;
35+
return Database.POSTGRESQL;
36+
}
37+
2938
@Test
3039
public void test() {
3140
Topic topic = doInJPA(entityManager -> {

core/src/test/java/com/vladmihalcea/book/hpjp/hibernate/type/json/sql/DefaultPostgreSQLJsonNodeBinaryTypeFetchTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void testFetchJsonPropertyUsingNativeSQL() {
3636
} catch (Exception e) {
3737
LOGGER.error("Failure", e);
3838

39-
Exception rootCause = (Exception) ExceptionUtil.rootCause(e);
39+
Exception rootCause = ExceptionUtil.rootCause(e);
4040
assertEquals("No Dialect mapping for JDBC type: 1111", rootCause.getMessage());
4141
}
4242
}

core/src/test/java/com/vladmihalcea/book/hpjp/util/exception/ExceptionUtil.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
public interface ExceptionUtil {
1818

19-
static List<Class<? extends Exception>> LOCK_TIMEOUT_EXCEPTIONS = Arrays.asList(
19+
List<Class<? extends Exception>> LOCK_TIMEOUT_EXCEPTIONS = Arrays.asList(
2020
LockAcquisitionException.class,
2121
LockTimeoutException.class,
2222
PessimisticLockException.class,
@@ -31,12 +31,12 @@ public interface ExceptionUtil {
3131
*
3232
* @return exception root cause
3333
*/
34-
static Throwable rootCause(Throwable t) {
34+
static <T extends Throwable> T rootCause(Throwable t) {
3535
Throwable cause = t.getCause();
3636
if ( cause != null && cause != t ) {
3737
return rootCause( cause );
3838
}
39-
return t;
39+
return (T) t;
4040
}
4141

4242
/**

0 commit comments

Comments
 (0)