java cannot store values retrieved from queries in variables.

Asked 2 years ago, Updated 2 years ago, 66 views

// Query
@NamedQuery(
            name = "id_select",
            query="SELECT rf.id FROM ReportFavo ASrf WHERErf.report_id=:report_id ANDrf.employee=:employee"
            )

// Store query values in variables
int id=em.createNameQuery("id_select", int.class)
                .setParameter("report_id", report_id)
                .setParameter ("employee", employee_id)
                .getSingleResult();

Error Message

HTTP Status 500 - Type specified for TypeQuery [int] is incompatible with query return type [class java.lang.Integer]

java sql

2022-09-30 21:43

1 Answers

If you are using a JPA-based framework (such as Hibernate), you can show it in the body or tag so that people who are familiar with it can easily find it.

Error Message

Type specified for TypedQuery [int] is incompatible with query return type [class java.lang.Integer]

That means

 The type (int) specified in the query with type is incompatible with the query return type (Integer)

This means that you should first try to modify it (the type specified in the type query).

Use intid=em.createNameQuery("id_select", Integer.class)//<-`Integer`
                .setParameter("report_id", report_id)
                .setParameter ("employee", employee_id)
                .getSingleResult();


2022-09-30 21:43

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.