0

Newbie Spring Boot developer looking for some assistance to resolve my blocker.

I am working on Spring Boot practice project that uses a H2 db.

The main objective of the project is to use API calls to get data from the database.

The majority of the API calls are returning data as expected but the filtering one is not.

I have looked on Stack overflow to try and resolve my error but have not been successful.

I have a compile error and this is stoping progress:

Caused by: org.h2.jdbc.JdbcSQLIntegrityConstraintViolationException: NULL not allowed for column "VALUE"; SQL statement:

INSERT INTO organization_application_lookup (organization_id, application_id) VALUES ('1', '1') [23502-200]

I am trying to introduce a filter query to the application whereby the results will return upon entering the first letter of the application name. When 'c' is entered applications starting with 'c' will be returned.

After reading this article I added the annotation @EmbeddedId to resolve the issue but unfortunately, it has not worked.

The point is, table organization_application_lookup should not really have a PK id column I don't think.

I created an object and table in the OrgAppMapper class as follows:

    package com.ciaranmckenna.companycoordinatorapp.model;

import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Table;

@Entity
@Table(name= "organization_application_lookup")
public class OrgAppMapper {

    @EmbeddedId
    @Column(name = "organization_id")
    private Long organisationId;
    @Column(name = "application_id")
    private Long applicationId;

    public OrgAppMapper() {
    }

    public OrgAppMapper(Long organisationId, Long applicationId) {
        this.organisationId = organisationId;
        this.applicationId = applicationId;
    }

    public Long getOrganisationId() {
        return organisationId;
    }

    public void setOrganisationId(Long organisationId) {
        this.organisationId = organisationId;
    }

    public Long getApplicationId() {
        return applicationId;
    }

    public void setApplicationId(Long applicationId) {
        this.applicationId = applicationId;
    }

}

The line private Long organizationId is causing a compile error. Stating that the 'Embedded' attribute type should not be 'Long'.

I have uploaded the project to codesandbox for the first time to make it easy for developers to help me out.

Link for project on codesandbox.io

codeskin
  • 147
  • 1
  • 1
  • 8

1 Answers1

0

Update!

Problem resolved.

I manually added the column and id values to the organization_application_lookup table.

The next issue on returning data was related to table mapping.

I changed the relationship between Platform and Application to @OneToMany

@OneToMany(mappedBy = "platform", cascade = CascadeType.ALL, orphanRemoval = true)

and the relationship with Application and Platform to @ManyToOne

@ManyToOne(cascade = CascadeType.ALL)

Thanks to anyone that took time to look at this.

codeskin
  • 147
  • 1
  • 1
  • 8