3

I m using jhipster v2. I have two entities (Father, Daughter), Father has a One-To-Many relationship with Daughter, and Daughter has a many-to-one relationship with Father. I have just made one modification to the generated java code :

  • I have configured the fetch type of the relationship between Father and Daughter to EAGER.

When I am getting all the Fathers, on the Java side I can see the Daughters collections attached to the Fathers, but I can't see the collection on the client(Anglarjs) side, Father javascript object doesn't have a 'daughters' property.

Is it normal? On server side :

@Entity
@Table(name = "T_CLIENT")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Client implements Serializable {
    ...
    @OneToMany(mappedBy = "client", fetch = FetchType.EAGER)
    @JsonIgnore
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
    private Set<Adresse> adresses = new HashSet<>();
    @OneToOne
    private Langue langue;
    ...
}

Client side (in my angularjs controller):

$scope.clients = Client.query(function(){
                        $log.info($scope.clients);
                    });

On client side I can see 'langue' property of client, but there is no 'adresses' property in client. I don't understand why.

Thanks for your answers.

user1260928
  • 3,269
  • 9
  • 59
  • 105

3 Answers3

4

Maybe it's due to the @JsonIgnore annotation. If you don't use a DTO to send your Client, Jackson will not serialize and deserialize your addresses data.

Solution 1: remove @JsonIgnore annotation.

Solution 2: create a DTO like UserDTO and use it to send to your client. I can advise you an awesome lib: MapStruct (http://mapstruct.org). It will help you to map your User object to UserDTO very easily. It's already use in the latest versions of JHipster.

Solution 3: If it's not a problem due to @JsonIgnore, but more about fetch the data with hibernate you will find your answer here: https://stackoverflow.com/a/19061378/4643869

Community
  • 1
  • 1
Thibaut Mottet
  • 414
  • 4
  • 15
2

You could also try

 @JsonIgnoreProperties({"client"})

Instead of @JsonIgnore, which will completely ignore it when it send jSON to the client.

natedaug
  • 81
  • 1
  • 1
0

If you want to use the default jhipster code and not modify the generated backend and leave fetch to lazy, then in your collection of fathers on the front side you must iterate that collection and query each father by Id to get a new father with all daughters loaded. Then do what you want with that data. Hopefully you don’t need so many , if so you need to use pagination when querying. Think about user experience, why do users need so much data.