speedment / jpa-streamer

JPAstreamer is a lightweight library for expressing JPA queries as Java Streams
GNU Lesser General Public License v2.1
339 stars 35 forks source link

Fieldgenerator yeilds ReferenceField instead of ComparableField #345

Closed julgus closed 1 year ago

julgus commented 1 year ago

Describe the bug The fieldgenerator uses an incorrect field type when building the JPAStreamer metamodel. This means that comparators such as .between() and .greaterThan() are unavailable when building predicates.

Expected behavior A field with the following definition should generate a ComparableField:

@Column(name = "length", columnDefinition = "smallint(5)")
@NotEmpty(message = "Length may not be empty", groups = {GroupA.class})
@NotNull(message = "Length may not be null", groups = {GroupA.class, GroupB.class})
@Size(min = 1, max = 300, message = "Length must be between 1 and 300 minutes characters long")
private Integer length;

Should generate:

    /**
     * This Field corresponds to the {@link Film} field "length".
     */
    public static final ComparableField<Film, Integer> length = ComparableField.create(
        Film.class,
        "length",
        Film::getLength,
        false
    );

**Actual behavior*** The field generates a ReferenceField:

    /**
     * This Field corresponds to the {@link Film} field "length".
     */
    public static final ReferenceField<Film, Integer> length = ReferenceField.create(
        Film.class,
        "length",
        Film::getLength,
        false
    );

How To Reproduce Add one of the annotations @Size, @NotNull or @NotEmpty to a JPA field.

Build tool Maven 3.9.0

JPAStreamer version JPAStreamer 3.0.2

JPA Provider Hibernate 6.0.2.Final

Java Version 11.0.17

julgus commented 1 year ago

The annotations are clearly disturbing how we are handling two different Integer fields:

image

For some reason, the annotations separate the package name java.lang from Integer. We probably just need to fix how we handle the parsing of type names.

julgus commented 1 year ago

Most interestingly this disturbance only occurs during Maven builds. During IntelliJ builds the annotations are followed by the qualified type name:

image