admin管理员组

文章数量:1278820

When running this with mvn spring-boot, i get the error.

Error Details:

Basic collection has element type 'uk.ac.rhul.cs2800.model.Grade' which is not a known basic type (attribute is not annotated '@ElementCollection', '@OneToMany', or '@ManyToMany')

As far as I can tell, the entity and relationships are annotated correctly so I don't understand why this is happening

This is my first time working with Spring or persistence, and as you can probably tell, this is university work, I really apologise if it's a badly asked question or lacking any info that I should add.

package uk.ac.rhul.cs2800.model;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToOne;

/**
 * class representing Grades.
 */
@Entity
public class Grade {

  @Id
  @GeneratedValue
  Long id;

  @ManyToOne
  @JoinColumn(name = "student_id")
  Student student;


  @OneToOne
  @JoinColumn(name = "module_id")
  Module module;



  public Module getModule() {
    return module;
  }

  public void setModule(Module module) {
    this.module = module;
  }

  public int getScore() {
    return score;
  }

  public void setScore(int score) {
    this.score = score;
  }



  int score;

  /**
   * constructor for Grade.
   *
   * @param score of grade as int.
   * @param module of grade as Module.
   */
  public Grade(int score, Module module) {
    this.score = score;
    this.module = module;
  }
}

When running this with mvn spring-boot, i get the error.

Error Details:

Basic collection has element type 'uk.ac.rhul.cs2800.model.Grade' which is not a known basic type (attribute is not annotated '@ElementCollection', '@OneToMany', or '@ManyToMany')

As far as I can tell, the entity and relationships are annotated correctly so I don't understand why this is happening

This is my first time working with Spring or persistence, and as you can probably tell, this is university work, I really apologise if it's a badly asked question or lacking any info that I should add.

package uk.ac.rhul.cs2800.model;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToOne;

/**
 * class representing Grades.
 */
@Entity
public class Grade {

  @Id
  @GeneratedValue
  Long id;

  @ManyToOne
  @JoinColumn(name = "student_id")
  Student student;


  @OneToOne
  @JoinColumn(name = "module_id")
  Module module;



  public Module getModule() {
    return module;
  }

  public void setModule(Module module) {
    this.module = module;
  }

  public int getScore() {
    return score;
  }

  public void setScore(int score) {
    this.score = score;
  }



  int score;

  /**
   * constructor for Grade.
   *
   * @param score of grade as int.
   * @param module of grade as Module.
   */
  public Grade(int score, Module module) {
    this.score = score;
    this.module = module;
  }
}
Share Improve this question edited Dec 9, 2024 at 7:52 Arf_code 5227 bronze badges asked Dec 8, 2024 at 17:00 EpicGaiaEpicGaia 176 bronze badges 2
  • 1 Add the full stacktrace and the entity thas has a collection of Grade as that is what is being complained about. Your Grade also must have a no-args constructor for JPA to work correctly. – M. Deinum Commented Dec 9, 2024 at 9:28
  • Ah no need but thanks. Yes, I didn’t realise it was a problem with the class that had a collection of Grade, but I annotated the relations there and the problem was solved – EpicGaia Commented Dec 9, 2024 at 16:37
Add a comment  | 

1 Answer 1

Reset to default 0

I hadn’t annotated the relations in another class which contained a collection of Grade

本文标签: