0

I have ignored saving a variable in entity class by @Transient annotation. The problem I'm facing after that is it cannot be serialized to JSON using JACKSON.

@Data
@Entity (name = "Pick")
@Table (name = "pick")
public class Pick {
    @Id
    @Column (name = "id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @Column (name = "vID")
    private Integer vD;

    @Column (name = "sID")
    private Integer sID;

    @Column (name = "rID")
    private Integer rID;

    @Column (name = "status")
    private String status;

    @Column (name = "category")
    private String category;

    @OneToMany
    @JoinColumn (name = "PickID")
    @Transient
    private List<Page> Pages;

}
Sajeer Babu
  • 1,103
  • 1
  • 9
  • 13
  • 1
    Try to use `@Transient` on getter method as suggested [here](https://stackoverflow.com/questions/32992952/transient-not-working-in-hibernate) – Alien Nov 29 '18 at 05:10
  • @Alien This will definitely fix the issue, but I'm not supposed to use getters and setters as a part of reducing boilerplate code in our application. Is there a way to do this without getters and setters? – Sajeer Babu Nov 29 '18 at 05:32
  • 1
    If you are serialising a database entity in order to transmit data to another system, you have just tightly coupled your internal implementation with the other system. If either changes, you have a problem. – Jason Nov 29 '18 at 05:46
  • 1
    You can install a custom ObjectMapper to override the transient field handling: https://stackoverflow.com/a/29109806/14955 – Thilo Nov 29 '18 at 07:08
  • @Thilo It is caching that variable but showing null as value. – Sajeer Babu Nov 29 '18 at 10:50

0 Answers0