Spring JPA: Jackson, avoid cyclic dependency
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 10 Jul 2016 17:57:02 +0000 (19:57 +0200)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 10 Jul 2016 17:57:02 +0000 (19:57 +0200)
SpringJava/JPA/src/main/java/de/spring/example/persistence/domain/Ad.java
SpringJava/JPA/src/main/java/de/spring/example/persistence/domain/AdDescription.java

index d1ad0df..7d90e0c 100644 (file)
@@ -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 :)
index 85f300c..b933c42 100644 (file)
@@ -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