Cannot declare List property in the JPA @Entity class. It says 'Basic' attribute type should not be a container
I know, that's an old question, but as it is still relevant, I will try to help with my solution.
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 String code;
private String name;
private List<AdditionalFee> additionalFees;
//getters, setters..
}
class AdditionalFee {
@Id
private int id;
//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 theprivate List<AdditionalFee> additionalFees;
field.
So, the working version looked like this:
@Entity
public class SomeFee {
@Id
private Long id;
private String code;
private String name;
@OneToMany
private List<AdditionalFee> additionalFees;
//getters, setters..
}
@Entity
class AdditionalFee {
@Id
private int id;
//getters, setters..
}
You can also use @ElementCollection
:
@ElementCollection
private List<String> tags;
Change @basic
to @OneToMany
for List types