I keep getting this error when building my maven project with dependencies:
Exception Description: The target entity of the relationship attribute
[template] on the class [class pt.ipleiria.dae.entities.Configuration]
cannot be determined. When not using generics, ensure the target entity is
defined on the relationship mapping.
I have these 2 entities with the following code: Configuration:
@ManyToMany(mappedBy="configurations")
private Template template;
private String name;
private ConfigurationState state;
private String version;
private String description;
private List<Module> modules;
private List<Resource> resources;
private List<String> parameters;
private List<String> extensions;
private String contrato;
Template(Owner of the relationship):
@ManyToMany
@JoinTable(name="TEMPLATE_CONFIGURATIONS",
joinColumns=
@JoinColumn(name="ID", referencedColumnName="ID"),
inverseJoinColumns=
@JoinColumn(name="ID", referencedColumnName="ID")
)
private List<Configuration> configurations;
I want to have a many to many relationship since a "Templates" holds several "Configurations", and "Configurations" can be in several "Templates"(of configurations).
Generally the exception you defined comes when you do not define Generics
while defining Many
side of the relationship like explained here
Though in your case, there is some other issue.
Since you have applied @ManyToMany
relationship between Configuration
and Template
, it should be defined like this in Configuration Entity.
@ManyToMany(mappedBy="configurations")
private List<Template> templates;
In case you have a requirement that Configuration can have only on template while a template can have multiple Configurations, you should go with OneToMany
relationship. In Configuration Entity you will have:
@ManyToOne(mappedBy="configurations")
private Template template;
And in Template Entity, you will have
@OneToMany
private List<Configuration> configurations;
Hope This Helps!!