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

There was an unforeseen conclusion to the JSON input while attempting to parse it

I am having an issue with the code in my get method. Can someone please help me troubleshoot and provide some guidance on how to solve it? app.get("/",function(req,res) { const url = "https://jsonplaceholder.typicode.com/users" ...

When the nesting in AngularJS ui-router becomes overwhelming

I've been in the process of refactoring a large application at work, and I've noticed significant similarities between different parts of the app that make me think nesting routes could be beneficial. However, as I continue to nest more and more, ...

Purge cookies from InternetExplorerDriver using Selenium WebDriver

Whenever I initialize my Internet Explorer instance, I rely on the following code snippet: public static WebDriver internetExplorerWebWDriver() { DesiredCapabilities returnCapabilities = DesiredCapabilities.internetExplorer(); returnCapabi ...

Challenges compiling 'vue-loader' in Webpack caused by '@vue/compiler-sfc' issues

The Challenge Embarking on the development of a new application, we decided to implement a GULP and Webpack pipeline for compiling SCSS, Vue 3, and Typescript files. However, my recent endeavors have been consumed by a perplexing dilemma. Every time I add ...

Every time I attempt to compile NodeJS, I encounter a compilation error

Within mymodule.js var fs = require('fs') var path = require('path') module.exports = function(dir, extension, callback){ fs.readdir(dir, function(error, files){ if(error) return callback(error) else { ...

Building a DOM element using jQuery

I have a function $(document).ready(function () { $("#btnhighlight").click(function () { var htext = $("#txthighlighttext").val(); $("#lstCodelist option").each(function () { var sp = $(this).text(); ...

Maximizing the potential of views and subviews in AngularJS

I'm a newcomer to AngularJS and facing some challenges with implementing multiple views. Can someone provide guidance on how to achieve this? My goal is to create a file explorer with two columns: the left column displays subfolders and files, while ...

Can you explain the meaning of this AJAX code snippet?

I've been researching online for information, but I'm struggling to find any details about the AJAX code snippet that I'm using: function getEmployeeFilterOptions(){ var opts = []; $checkboxes.each(function(){ if(this.checke ...

Converting HTML table data into a JavaScript array

On my website, I have an HTML table that displays images in a carousel with their respective positions. The table utilizes the jQuery .sortable() function to allow users to rearrange the images by dragging and dropping. When an image is moved to the top of ...

transferring data between two angular modules on a single webpage

Creating several nested modules on a page is something I have done before, for example: module A{ module B{ ..... } } I am wondering if it's feasible to pass values from module A to module B in this setup. I found guidance on how to cre ...

The PHP header() function is not properly redirecting the page, instead it is only displaying the HTML

After double checking that no client sided data was being sent beforehand and enabling error reporting, I am still encountering issues. The issue revolves around a basic login script with redirection upon validation. <?php include_once "database- ...

Deleting table rows after an object has been removed in AngularJSNote: Using

My AngularJS application retrieves a list of JSON objects and displays them in a table. Each row in the table includes a "Delete" button that triggers an ng-click method: <td><a ng-click="testButton()" class="btn btn-danger btn-mini">Delete&l ...

jQuery struggles to locate the active class within the Bootstrap slider

Want to make some changes to the Bootstrap slider? Here is the HTML Code and jQuery: <div id="carousel-slider2" class="carousel slide bs-docs-carousel-example"> <ol class="carousel-indicators"> & ...

Error encountered: npm process ended unexpectedly with error code ELIFECYCLE and errno 2

Whenever I attempt to run - npm run dev in my command prompt, I encounter the following error: Insufficient number of arguments or no entry found. Alternatively, run 'webpack(-cli) --help' for usage info. Hash: af4cfdb00272137cb4d3 Version: web ...

Error encountered when trying to update Express Mongoose due to duplicate key

In my MongoDB database, I have a unique field called mail. When attempting to update a user, I encounter an issue where if I do not change the mail field, it triggers a duplicate key error. I need a solution where it is not mandatory to always modify the ...

EJS not displaying object values properly

I'm currently in the process of setting up a blog and I want to create a page that displays the titles of all the articles I've written. For example: List of Articles: * Title: Article 1 * Title: Article 2 * Title: Article 3 Below is my Schem ...

Tips for importing font files from the node_module directory (specifically otf files)

We cannot seem to retrieve the fonts file from the node module and are encountering this error message. Can't find 'assets/fonts/roman.woff2' in 'C:\Projects\GIT2\newbusinessapp\projects\newbusinessapp\src ...

"Utilizing regular expressions in JavaScript to check for multiple

I have a function that replaces HTML entities for & to avoid replacing &amp; but it still changes other entities like &, ", >, and <. How can I modify the regex in my function to exclude these specific entities? &apos; &quo ...

I would like to check if a given username and password exist in my JSON data

Trying different methods but not achieving the desired outcome. I have limited knowledge about JSON, gathered some information from online sources. var loginDataList = [{ "username": "abc", "password": "abc123" }, { "username": "richa", "p ...

Invoking a function that is declared in a fetch request from an external source beyond the confines of the fetch itself

I am currently struggling with calling a function that is defined inside an API Fetch response function. My code sends an API fetch request to the GitHub API to retrieve a repository tree in JSON format. The problem arises when I try to call a function def ...