I have a JPA @Entity class Place
, with some properties holding some information about a place, such as name of place, description, and URLs of some images.
For the URLs of images, I declare a List<Link>
in my entity.
However, I am getting this error:
Basic attribute type should not be a container.
I tried to remove @Basic
, but the error message is still there. Why does it shows this error?
An entity can aggregate objects together and effectively persist data and related objects using the transactional, security, and concurrency services of a JPA persistence provider.
The @Entity annotation specifies that the class is an entity and is mapped to a database table. The @Table annotation specifies the name of the database table to be used for mapping.
Entities in JPA are nothing but POJOs representing data that can be persisted to the database. An entity represents a table stored in a database. Every instance of an entity represents a row in the table.
You are most likely missing a relational (like @OneToMany
) annotation and/or @Entity
annotation.
I had a same problem in:
@Entity public class SomeFee { @Id private Long id; private List<AdditionalFee> additionalFees; //other fields, getters, setters.. } class AdditionalFee { @Id private int id; //other fields, getters, setters.. }
additionalFees
was the field causing the problem.
What I was missing and what helped me are the following:
@Entity
annotation on the Generic Type argument (AdditionalFee
) class;@OneToMany
(or any other type of appropriate relation fitting your case) annotation on the private List<AdditionalFee> additionalFees;
field.So, the working version looked like this:
@Entity public class SomeFee { @Id private Long id; @OneToMany private List<AdditionalFee> additionalFees; //other fields, getters, setters.. } @Entity class AdditionalFee { @Id private int id; //other fields, getters, setters.. }
You can also use @ElementCollection
:
@ElementCollection private List<String> tags;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With