Java persistence (Ebean) serialize generated value to Json -


i have 2 entities , onetomany relationship between them. first:

@entity public class trip extends model {      ...      @onetomany(cascade = cascadetype.all)     public list<category> categories = new arraylist<>(); } 

the second one:

@entity public class category extends model {      ...      @manytoone     public trip trip; } 

so, ebean automatically generates trip_id column category table.

now need serialize category entity/object json (with trip_id including). how can it? trying manually create trip_id field, received duplicate exception.

you have one-directional relations. should change them bi-directional. there should be:

@entity public class trip extends model {      ...      @onetomany(cascade = cascadetype.all, mappedby="trip")     public list<category> categories = new arraylist<>(); }  @entity public class category extends model {      ...      @manytoone     public trip trip;      @onetomany(mappedby="category")     public list<place> places = new arraylist<>(); }  @entity public class place extends model {      ...      @manytoone     public category category;  } 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -