vendredi 7 décembre 2018

Hibernate/reflection issue in OneToMany relation: IllegalArgumentException

When I try to save an object on the n-side that has the object on the 1-side set, I receive the following error:

Dec 07, 2018 10:37:07 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.orm.jpa.JpaSystemException: Error accessing field [public java.lang.String eu.jaas.document.Document.id] by reflection for persistent property [eu.jaas.document.Document#id] : 17842965-4ea8-41b6-9653-110965f6db13; nested exception is org.hibernate.property.access.spi.PropertyAccessException: Error accessing field [public java.lang.String org.myorg.document.Document.id] by reflection for persistent property [org.myorg.document.Document#id] : doc123] with root cause
java.lang.IllegalArgumentException: Can not set java.lang.String field eu.jaas.document.Document.id to java.lang.String
    at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
    at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)

The 1-side Java object is defined as follows:

@Entity
public class LawCase {
    ..
    @OneToMany(mappedBy = "lawcase")
    public @Setter Set<Document> documents = new HashSet<>();
    ..
}

And the n-side:

public class Document {
    ..
    @Id
    public String id;

    @ManyToOne
    @JoinColumn(name="lawcase")
    public GenCase lawcase;
    ..
}

I use springBoot.version 2.1.1.RELEASE and tried with Java8 and Java11. It looks very much like a common hibernate use-case to me, the only "anomaly" might be that I have also lombok annotations on the data classes. I am sure I overlooked some very simple issue, but was blind for the last few days.





Aucun commentaire:

Enregistrer un commentaire