From 18a269776e79711af0e8ab7ffd3126836bfc4677 Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Sun, 10 Jul 2016 19:57:02 +0200 Subject: [PATCH] Spring JPA: Jackson, avoid cyclic dependency --- .../JPA/src/main/java/de/spring/example/persistence/domain/Ad.java | 3 +++ .../main/java/de/spring/example/persistence/domain/AdDescription.java | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/SpringJava/JPA/src/main/java/de/spring/example/persistence/domain/Ad.java b/SpringJava/JPA/src/main/java/de/spring/example/persistence/domain/Ad.java index d1ad0df..7d90e0c 100644 --- a/SpringJava/JPA/src/main/java/de/spring/example/persistence/domain/Ad.java +++ b/SpringJava/JPA/src/main/java/de/spring/example/persistence/domain/Ad.java @@ -24,11 +24,14 @@ import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; import de.spring.example.persistence.converters.OffsetDateTimeAttributeConverter; @Entity @Table(name="ad", schema="mybatis_example") +@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="jsonId") // 1. Named query is JPL. It is portable. // 2. Instead of annotating the domain class we should be using @Query annotation at the query method // because it should be cleaner :) diff --git a/SpringJava/JPA/src/main/java/de/spring/example/persistence/domain/AdDescription.java b/SpringJava/JPA/src/main/java/de/spring/example/persistence/domain/AdDescription.java index 85f300c..b933c42 100644 --- a/SpringJava/JPA/src/main/java/de/spring/example/persistence/domain/AdDescription.java +++ b/SpringJava/JPA/src/main/java/de/spring/example/persistence/domain/AdDescription.java @@ -16,8 +16,12 @@ import javax.validation.constraints.Max; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; + @Entity @Table(name="ad_description", schema="mybatis_example") +@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="jsonId") public class AdDescription implements Serializable { @Id -- 2.1.4