0

Before saving enter image description here

After saving enter image description here

@Entity
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class Notification {


  @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long notificationId;
    private Long businessId;
    private String actionBy;
    private String date;
    private String notification;
    public ArrayList<UserNotification> user;

  //constructor here

  //getters setters here
}

and UserNotification.java is

public class UserNotification {
private Long id;
private String user;
private String notifCount;
//getters setters here
}

I don't know why is it returning null. At what point I made a mistake?

EDIT:

 var usersObj=[];
        BusinessRoleService.getByBusinessId($sessionStorage.businessRole.business).then(function(response){
            if(response.status==200){
                for(var x=0;x<response.data.length;x++){
                    usersObj.push({id: x, user: response.data[x].userId, notifCount: $scope.notification});
                }


            }
        });

        var obj = {
            "businessId": businessId,
            "actionBy": user,
            "date": date,
            "notification": user+" "+action,
            "user": usersObj
        }

then I will pass the obj to my service to save

This is what my database looks like after saving

enter image description here

Mark
  • 293
  • 1
  • 11
  • 25

1 Answers1

2

In your Notification Java object, the user property has the @Transient annotation. Which means it won't be persisted.

So, the property is null in the response of your controller.

As other have said, you also have a difference in your JavaScript and Java structure. In your Notification java object, your list should be named users

After your last edit :

Why is UserNotification not an @Entity? Also you need to tell JPA what kind of relationship ties Notification to UserNotification. My guess is there's a bunch of annotations missing on both classes. Read this :https://en.wikibooks.org/wiki/Java_Persistence/OneToMany

Guillaume Georges
  • 3,878
  • 3
  • 14
  • 32