rsql-jpa-specification
rsql-jpa-specification copied to clipboard
Unexpected value type querying for Long
Greetings! I am using the rsql-jpa-spring-boot-starter with spring boot 3. So far all my queries work with no issues, but now I am trying to do something as simple as
query = "id==1";
repository.findAll(RSQLJPASupport.toSpecification(query));
And I get the following error:
java.lang.AssertionError: Unexpected value type (expected : java.lang.Long) : 1 (java.lang.String)
at org.hibernate.sql.exec.internal.JdbcParameterBindingImpl.<init>(JdbcParameterBindingImpl.java:23)
at org.hibernate.sql.exec.spi.JdbcParameterBindings.createAndAddBinding(JdbcParameterBindings.java:97)
at org.hibernate.type.BasicType.forEachDisassembledJdbcValue(BasicType.java:135)
at org.hibernate.metamodel.mapping.Bindable.forEachJdbcValue(Bindable.java:197)
I've read all the docs in the read me and tried other ways such as >1=;<=1 but anything I do with a number for an ID I get the above error.
EDIT I believe I figured out the issue, my entity extends an AbstractEntity that holds the ID value. So the classes are as follow:
@MappedSuperclass
@NoArgsConstructor
@Getter
@Setter
@Accessors(chain = true)
@EqualsAndHashCode
public class AbstractEntity<T> {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
protected T id;
@Version
@Column(columnDefinition = "int default 0")
protected Integer version = 0;
}
The entity I am querying for is this:
@Entity
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@RequiredArgsConstructor(staticName = "of")
@Accessors(chain = true)
public class Instance extends AbstractEntity<Long> {
@NotNull
@NonNull
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(foreignKey = @ForeignKey(name = "FK_definition_id"))
private Definition Definition;
}
I am using Lombok's @Data for all getters and setters. The way I have it setup returns me the error, however if I do not extend AbstractEntity and put the ID in my Instance class, the query "id==1" actually does work.
Is there a way a fix can be put into this? Or do I have to have the ID in every entity I wish to query with RSQL? I'll continue testing on my end and see if I can find any other solutions.
Thank you!