Guide to storing a collection in an object with Java

Before the changes were saved https://i.stack.imgur.com/hjpXa.jpg

After the changes were saved https://i.stack.imgur.com/xABzN.jpg

@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 goes here

  //getters and setters go here
}

Additionally, here is the UserNotification.java file:

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

I am encountering an issue where it returns null. I am trying to identify my mistake.

UPDATE:

 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
        }

Once the object is created, I will proceed to pass it to my service for saving.

Below is a snapshot of how my database appears after the updates have been saved:

https://i.stack.imgur.com/c1Hzk.jpg

Answer №1

Within your Notification Java object, the user attribute is marked with the @Transient annotation, indicating that it will not be stored in the database.

As a result, when the controller returns a response, this particular property will be null.

Furthermore, there appears to be a discrepancy between the structures of your JavaScript and Java code. In your Notification Java class, the list should ideally be named users.

Following your latest update:

Have you considered making UserNotification an @Entity? Additionally, ensure that JPA is informed about the type of relationship between Notification and UserNotification. It is likely that certain annotations are missing from both classes. You may find this resource helpful:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I'm interested in exploring different database implementation patterns in JavaScript. What kinds of approaches can I consider?

As someone who is relatively new to exploring JavaScript, I have been immersed in experimenting with a node test app and MongoDB. I am eager to delve into the database aspect of the app but finding myself uncertain about the most commonly used patterns in ...

Alert for any shift in the main task at hand

As a beginner in mobile development, I kindly ask for some understanding if I overlook any obvious details. My main objective now is to find a way to monitor a foreground task on both iOS and Android. To elaborate, I want my program to perform the followi ...

Encountering an unexpected token in the JSON file at the very start is causing an

An unexpected error has occurred, showing the following message:- Uncaught SyntaxError: Unexpected token u in JSON at position 0 The code causing the error is as follows:- import { useEffect, useState } from "react"; import { useNavigate, usePar ...

What sets apart Keys.UP from Keys.ARROW_UP in selenium webdriver?

I'm curious about the distinction between Keys.UP and Keys.ARROW_UP in Selenium WebDriver. Upon testing both keys, I've noticed that they appear to exhibit identical behavior and functionality. This has prompted a couple of questions: Why are ...

Ensure that data is accurately confirmed using an alternative mode within react-hook-form

Currently utilizing react-hook-form with the primary validation mode set to "onChange": const formMethods = useForm({ mode: 'onChange' }) I am looking to modify the mode property for a specific input nested within a Controller, but I am unsure ...

Trigger the fire event on .click() except when text is being selected

I am currently working on a chat box project and I want the input field within the message area to automatically get focused when the user clicks anywhere in the chat box. However, I don't want this functionality to interfere with text selection for c ...

Utilizing external imports in webpack (dynamic importing at runtime)

This is a unique thought that crossed my mind today, and after not finding much information on it, I decided to share some unusual cases and how I personally resolved them. If you have a better solution, please feel free to comment, but in the meantime, th ...

What is the process for running an Angular 1.4 application on a system with Angular 6 installed?

After installing Angular 6 with CLI, I realized that my project was written in Angular 1.4. How do I go about running it? ...

Selenium: Issue encountered when attempting to establish a remote session for Chromedriver 97

I encountered this issue: Starting ChromeDriver 97.0.4692.71 (adefa7837d02a07a604c1e6eff0b3a09422ab88d-refs/branch-heads/4692@{#1247}) on port 17892 Only local connections are allowed. Please see https://chromedriver.chromium.org/security-considerations fo ...

Monitoring an object with Angular.js $watch does not detect the addition of a new property as a change

Within my Angular.js directive, I have the following code snippet: scope.$watchCollection(function(){ return StatusTrackerService.eventCollection }, function(){ console.log("ssssssssssss"); console.log(StatusTracker ...

Firefox fails to render SVG animation

Currently, I'm attempting to incorporate this unique animation into my website: http://codepen.io/dbj/full/epXEyd I've implemented the following JavaScript code in order to achieve the desired effect: var tl = new TimelineLite; tl.staggerFromTo ...

Experience a seamless transition to Hibernate 3.6 when encountering issues with reverse engineering

I have been scouring multiple websites trying to find a solution to this problem, but I'm hitting a dead end. It seems like it's impossible to fix. Every time I encounter the error Caused by: java.lang.IncompatibleClassChangeError: Found interfac ...

Learning how to integrate Next.js, React.js, and Redux into an HTML page for an enhanced user

My current project is built on Asp.Net MVC, but the technology used is not crucial. I integrated react.js and redux for searching a section of my html page using a cdn link. Now, I am considering deploying the server side of the application with next.js. ...

Retrieve the concealed division element's HTML content along with its formatting

Help needed with appending a hidden div with its styles intact. Despite using the code provided below, the appended div does not retain its styles. Any suggestions for an alternative method? var warningMessage = $('#warningDiv').html() fun ...

I'm having trouble with my AJAX Update Panel. Can someone please help me figure out what I'm doing wrong?

--------------Handling Gridviews DataBound Event ----------------- protected void grdShowCallingList_DataBound(object sender, EventArgs e) { if (grdShowCallingList.Rows.Count > 0) { foreach (GridViewRow row in grdShowCallingList.Rows) ...

Tricks for preventing axios from caching in GET requests

I am utilizing axios in my React-Native application Firstly, I set up the headers function setupHeaders() { // After testing all three lines below, none of them worked axios.defaults.headers.common["Pragma"] = "no-cache"; axios.defaults.heade ...

Tips for managing the user model in an AngularJS application

During my process of refactoring a AngularJS application, I noticed that most data is currently being stored in the $rootScope. In previous Angular projects, I typically created a dedicated Service for each model and then instantiated it within a Controll ...

Eliminate any undefined data in the popup map of Javascript

I am working with JSON data that is being displayed in a pop-up on a map. In cases where there is missing data (Visibility), the word undefined appears in the pop-up. Is there a way to remove the undefined text so that it does not show up in the pop-up? ...

Upgrading to Bootstrap 5 and customizing the collapse button text upon click

I've spent a lot of time searching for a solution to my problem, but all the advice I found is for bootstrap 3 and 4, not version 5. Below is the code I am currently using: <div class="p-3">9 Members Online <a class="p-1 btn ...

Is NextJS on-demand revalidation compatible with Next/link?

https://nextjs.org/docs/basic-features/data-fetching/incremental-static-regeneration#on-demand-revalidation According to the NextJS documentation, it appears that on-demand cache revalidation should function properly with regular <a> tags and when t ...