| Let's assume I have a simple entity class:
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Entity;
@Entity
public class EntryContainer {
private List<ScheduleEntry> entries = new ArrayList<>();
public List<ScheduleEntry> getEntries() {
return entries;
}
public void setEntries(List<ScheduleEntry> entries) {
this.entries = entries;
}
}
This generates the following Metamodel:
import javax.annotation.Generated;
import javax.persistence.metamodel.ListAttribute;
import javax.persistence.metamodel.StaticMetamodel;
@Generated(value = "org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor")
@StaticMetamodel(EntryContainer.class)
public abstract class EntryContainer_ {
public static volatile ListAttribute<EntryContainer, ScheduleEntry> entries;
}
Great! But now let's add a method to the entity class:
public Set<ScheduleEntry> getEntries(Predicate<? super ScheduleEntry> filter) {
return entries.stream().filter(filter).collect(Collectors.toSet());
}
Notice that this is completely okay for Hibernate ORM. Because this method accepts parameters, there is no need to annotate this method with @Transient, as it is skipped by Hibernate ORM anyway. But not so with hibernate-jpamodelgen! hibernate-jpamodelgen creates a Metamodel including this method. Worse yet, this method has the same name as the proper getter-method for Hibernate ORM, so hibernate-jpamodelgen replaces the correct attribute inside the Metamodel with the wrong attribute of this wrongly included method:
@Generated(value = "org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor")
@StaticMetamodel(EntryContainer.class)
public abstract class EntryContainer_ {
public static volatile SetAttribute<EntryContainer, ScheduleEntry> entries;
}
Notice that the correct ListAttribute has been overwritten with the wrong SetAttribute. I think hibernate-jpamodelgen should skip methods that accept parameters for metadata generation. |