5
   Posts Model

  /*set many to one relation with Privacy_Level model*/
  @ManyToOne//(fetch = FetchType.LAZY)
  @JoinColumn(name = "privacy_level_id",referencedColumnName = "id", insertable = false, updatable = false)
  public Privacy_Level privacy_level_t;

-------------------------------------------------------------------------------------------------------------
  Privacy_Level Model

  /*set one to many relation with Posts model*/
  @OneToMany(mappedBy = "privacy_level_t")
  public List<Posts> posts;

  /*set many to one relation with Table_Status model*/
  @ManyToOne
  @JoinColumn(name = "status",referencedColumnName = "id", insertable = false, updatable = false)
  public Table_Status table_status;
--------------------------------------------------------------------------------------------------------------
  Table_Status Model

  /*set many to one relation with Privacy_level table*/
  @OneToMany(mappedBy = "table_status")
  public List<Privacy_Level> privacy_level;

I have linked the Posts model with the Privacy_Level model using a manytoone/onetomany relationship while the Table_Status model with Privacy_Level model using a many to one/one to many relationship as well.

Now I need to access a value in Table_Status through a Posts object as shown below:

post.privacy_level_t.table_status.getDes() 

This worked fine in Play 2.5 but after migrating to Play 2.6 this returns a null value. I can however access a Privacy_Level value using post.privacy_level_t.getDes() but trying to access a value one step further down the hierarchy line returns an error.

I checked through the Play migration guide but could not find anything related to this issue.

UPDATE

This is the function that i'm having the mentioned issue.

 private boolean getPostsDetail(List<Posts> post_list){
       home_page_posts = Json.newArray();
       for(Posts post:post_list) {

           if(!post.privacy_level_t.table_status.getDes().equals("activated")) continue;
           switch (post.post_types.getPost_type_name()){
               case "Star_Rating":
                   getArrayNodeForNonAnonyStarPost(post);
                   continue;
               case "Text_Poll":
                   getArrayNodeForNonAnonyPollPost(post);
                   continue;
               case "Image_Poll":
                   getArrayNodeForNonAnonyPollPost(post);
                   continue;
               case "star_rating_post_other_detail":
                   getArrayNodeForAnonyStarPost(post);
                   continue;
               default:
                   continue;
           }
       }
       return true;
   }

The code inside the if condition returns a NullPointerException in Play 2.6

CraZyDroiD
  • 6,622
  • 30
  • 95
  • 182
  • What is `getDes()` ? Can you share your code Model by Model instead of putting everything together? It's confusing. – Zenoo Jun 22 '18 at 09:04
  • @Zenoo getDes() is a public getter method inside the Table_Status model. This code works fine in Play 2.5 but after migrating to 2.6 it stopped working. I broke down the relationships according to their models/classes as you requested. – CraZyDroiD Jun 23 '18 at 10:51
  • In your example, how do you fetch `post` ? Do you use a `Finder` ? Please share the context of the code producing the error. – Zenoo Jun 23 '18 at 10:53
  • Finder method in Play 2.5: public static Finder find = new Finder(Long.class, Privacy_Level.class); Finder method in Play 2.6: public static Finder find = new Finder(Privacy_Level.class); – CraZyDroiD Jun 23 '18 at 11:13
  • Can you also share where the `post_list` parameter is created/fetched ? – Zenoo Jun 23 '18 at 11:16
  • @Zenoo The posts_list parameter is successfully received inside the function. I can access post.privacy_level.getDes() but the error occurs when I try to access post.privacy_level.table_status.getDes(). If I call post.privacy_level.getDes() and then call post.privacy_level.table_status.getDes() in the preceeding line, the value is successfully returned! – CraZyDroiD Jun 23 '18 at 11:29
  • @Zenoo Correction: not in the preceeding line but in the following line – CraZyDroiD Jun 23 '18 at 11:36
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/173672/discussion-between-zenoo-and-crazydroid). – Zenoo Jun 23 '18 at 12:33

0 Answers0