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 Answer
Reset to default 0I hadn’t annotated the relations in another class which contained a collection of Grade
本文标签:
版权声明:本文标题:java - Basic collection has element type <class> which is not a known basic type (attribute is not annotated & 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736128927a1906023.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
Grade
as that is what is being complained about. YourGrade
also must have a no-args constructor for JPA to work correctly. – M. Deinum Commented Dec 9, 2024 at 9:28