java.util.HashMap cannot be cast to Object
java.lang.ClassCastException: java.util.HashMap cannot be cast to custom data class
java.util.HashMap cannot be cast (android studio, firebase,java)
java.util.HashMap cannot be cast to com.google.android.gms.maps.model.LatLng
java.lang.ClassCastException: java.util.HashMap cannot be cast to in spring boot microservice
First, let's create constructors with parameters
that you need for RoomInvestigatorMapping
and Employee
, then you should add these lines:
For RoomInvestigatorMapping
public RoomInvestigatorMapping() {
// Empty constructor
}
public RoomInvestigatorMapping(String sEmpName, Integer nEmpId,
Integer nRoomInvestigatorMappingId,
Integer nRoomAllocationId) {
this.employee = new Employee(sEmpName, nEmpId);
this.nRoomInvestigatorMappingId = nRoomInvestigatorMappingId;
this.nRoomAllocationId = nRoomAllocationId;
}
For Employee
public Employee() {
// Empty constructor
}
public Employee(String sEmpName, Integer nEmpId) {
this.sEmpName = sEmpName;
this.nEmpId = nEmpId;
}
Second, let's modify your query like:
@Query("SELECT new com.spacestudy.model.RoomInvestigatorMapping(emp.sEmpName as sEmpName, emp.nEmpId as nEmpId,"
+ " roomInvest.nRoomInvestigatorMappingId as nRoomInvestigatorMappingId,"
+ " roomInvest.nRoomAllocationId as nRoomAllocationId) "
+ "FROM RoomInvestigatorMapping as roomInvest "
+ "INNER JOIN Employee as emp "
+ "ON roomInvest.nInvestigatorId = emp.nEmpId ")
List<RoomInvestigatorMapping> findInvestigatorUsingName();
java.util.HashMap cannot be cast to java.util.ArrayList
Hashmap: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.String
You are getting id
field from client with type of Long
and trying to put it into an int
type.
If you can change Product
class, I recommend to change its id
field type to long
so that no casting is needed also you might face data loss in casting long
to int
.
by the way if you can not change your code or don't want to, here you can fix the problem:
instead of:
int id = prod.containsKey("id") && !prod.get("id").isEmpty() ? Integer.parseInt((String) prod.get("id")) : 0;
use this:
int id = prod.containsKey("id") && !prod.get("id").isEmpty() ? (int) prod.get("id") : 0;
good luck
Related Topics
How to Show Alert in a Jsp from a Servlet and Then Redirect to Another Jsp
Javac Option to Compile All Java Files Under a Given Directory Recursively
Refreshing Existing Windows in Java Swing
Enable Jackson Deserialization of Empty Objects to Null
Failed to Process Import Candidates for Configuration Class
Round Off a Double While Maintaining the Trailing Zero
How to Exit an Android App Programmatically
How to Map an Auto Increment Field in Hibernate
Converting Excel File (Xlsx) into Json
Making a Mocked Method Return an Argument That Was Passed to It
Read Huge Excel File(500K Rows) in Java
Kafka: Failed to Update Metadata After 60000 Ms
How to Clean Project Cache in Intellij Idea Like Eclipse'S Clean
Intellij Idea - Gradle: Execution Failed for Task ':Compilejava'
Password Encrypt and Decrypt Using Spring-Security
How to Split a Huge Zip File into Multiple Volumes
Testing Two Json Objects for Equality Ignoring Child Order in Java