There is this class:
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private long id;
private int key;
private String text;
private Tag[] tags;
private String title;
private boolean valid;
public Activity(int key, String text, Tag[] tags, String title) {
this.key = key;
this.text = text;
this.tags = tags;
this.title = title;
valid = true;
}
which has an array of Tag associated with it. Tag looks like this:
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private long id;
private long activityId;
private String keyword;
public Tag(String keyword){
this.keyword = keyword;
activityId = -1;
}
Both Activity and Tag are Entitys and also both have Repositorys:
public interface TagRepository extends CrudRepository<Tag, Long> {
}
public interface ActivityRepository extends CrudRepository<Activity, Long> {
}
There is this create - method which stores an Activity Object in the database:
@PostMapping
public Activity create(@RequestBody Activity input) {
if(input.getTags() != null) {
for(Tag t : input.getTags()) {
t.setActivityId(input.getId()); //associate which activity has which tags
tagRepository.save(t);
}
}
return activityRepository.save(input);
}
I transmit this JSON via POST:
{
"key":2,
"text":"Hello",
"tags":[{
"keyword":"h"
},{
"keyword":"b"
}
],
"title":"world"
}
But I get this error:
"status": 500,
"error": "Internal Server Error",
"exception": "org.springframework.orm.jpa.JpaSystemException",
"message": "could not serialize; nested exception is org.hibernate.type.SerializationException: could not serialize"
Both classes have getter/setter for each member variable and also both have default ctors, I just didn't show them here to keep the question as short as possible.
org.hibernate.AnnotationException: List/array has to be annotated with an @OrderColumn (or @IndexColumn): base.Activity.tags