I am using ebean with Play Framework 2.4
I cant understand where is the problem. Here are a simplified version of my two beans:
@Entity
public class ArtifactEntry extends Model {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public int id;
@play.data.validation.Constraints.Required
public String name;
@ManyToMany(mappedBy = "artifacts")
public List<TimestampEntry> timestamps = new ArrayList<TimestampEntry>();
}
And my other bean:
@Entity
public class TimestampEntry extends Model {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public int id;
@play.data.validation.Constraints.Required
@Index
public String timestamp;
public Date timestampDate;
@play.data.validation.Constraints.Required
@Index
public String buildNumber;
@ManyToMany(cascade = CascadeType.ALL)
public ArtifactsList artifacts = new ArtifactsList();
public static class ArtifactsList extends ArrayList<ArtifactEntry> {
}
}
The error message is:
1) Error injecting constructor, javax.persistence.PersistenceException: Error on models.ArtifactEntry.timestamps. mappedBy property [models.TimestampEntry.artifacts] is not a ManyToMany?
EDIT: After having researched more, the problem is clearly the fact that "artifacts" is not the immediate type "List" but a subclass of it. Ebean is not that smart. Any solution to this?
Ok, as I have edited in my previous post, the problem seem to be that EBeans does not read the type hierarchy of the attributes up to match a ManyToMany relation ship. It simply has to match on both classes.
In a first place, I needed to implement this with an empty class extending ArrayList, so that I can register this class with a custom SimpleFormatter (as I did not want to parse all the List in this way).
I ended up removing the "ArtifactsList" and instead, of using a SimpleFormatter with List, I have changed it to use an AnnotationFormatter, so that only only my annotated attribute gets parsed in this custom formatter.