I am trying to setup connections to query a ready only database using Spring Data JDBC. My interface looks something like the following
@Repository
interface BaseRepository extends CrudRepository<DeliveryTask, String> {
@Query(value = "SELECT DELIVERY_TASK_ID FROM DELIVERY_TASK WHERE ORDER_ID = :orderId")
List<DeliveryTask> findByOrderId(@Param("orderId") String orderId);
}
My entity is defined as such
@Table("DELIVERY_TASK")
public class DeliveryTask {
@Column("DELIVERY_TASK_ID") @Id
String deliveryTaskId;
@Column("ORDER_ID")
String orderId;
DeliveryTask(){}
public DeliveryTask(String deliveryTaskId, String orderId){
this.deliveryTaskId = deliveryTaskId;
this.orderId = orderId;
}
public String getOrderId() {
return orderId;
}
public DeliveryTask setOrderId(String orderId) {
this.orderId = orderId;
return this;
}
public String getDeliveryTaskId() {
return deliveryTaskId;
}
public DeliveryTask setDeliveryTaskId(String deliveryTaskId) {
this.deliveryTaskId = deliveryTaskId;
return this;
}
}
The DELIVERY_TASK table has a PK DELIVERY_TASK_ID that is of type RAW. When I query on this field I am able to return results and the ORDER_ID is returned properly as well. When I query on ORDER_ID however, which is of type VARCHAR2, returns null.
The ORDER_ID I am querying for is a simple numeric string such as “123”. This record definitely exists in the DB and submitting the query directly in other projects via plain java.sql does return results. I am left confused as to what the problem could be.
I have trace logs enabled and I can see this is what is printed
Executing prepared SQL statement [SELECT DELIVERY_TASK_ID FROM DELIVERY_TASK WHERE ORDER_ID = ?]
Setting SQL statement parameter value: column index 1, parameter value [123], value class [java.lang.String], SQL type 12
Things I have tried:
-
Running the query with TRIM()
-
Running using LIKE instead of =
-
Reverting Java and JDBC driver versions
Oracle and dependencies version:
-
Oracle Database 12c Standard Edition Release 12.1.0.2.0
-
Java 17 + ojdbc 11.21.9
-
spring-data-jdbc 3.3.0
I have also tried
-
Java 8 + ojdbc 8.21.3
-
spring-data-jdbc 2.3.3
Any insights will be appreciated as to why querying against this field in particular returns null.
Taiguar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.