Reputation: 1812
When I try to run:
List<MappingInstruction> result = emFactory.get()
.createQuery("FROM " + MappingInstruction.class.getSimpleName() + " c where c.mapping = :mapping",
MappingInstruction.class).setParameter("mapping", mappingInfo.getId()).getResultList();
I get:
Service exception executing action "MappingAddAction", java.lang.IllegalArgumentException: Parameter value [5118] did not match expected type [com.vernuso.trust.server.domain.clientimport.MappingInfo (n/a)]
I debugged in Eclipse and mappingInfo.getId()
does return 5118.
Can someone please help me understand why it expects the type MappingInfo
instead of long
?
I have two tables as shown in the image below. MappingInfo has One-To-Many relationship with MappingInstruction table.
Upvotes: 0
Views: 8535
Reputation: 994
Look closely:
List<MappingInstruction> result = emFactory.get()
.createQuery("FROM " + MappingInstruction.class.getSimpleName() + " c where c.mapping = :mapping",
MappingInstruction.class).setParameter("mapping", mappingInfo.getId()).getResultList();
You are fetching from MappingInstruction Entity. In the where condition, c.mapping is of type MappingInfo. Please check the datatype of mapping variable inside MappingInstruction class.
Because c.mapping is of type MappingInfo,but you are passing mappingInfo.getId() which is long, the ava.lang.IllegalArgumentException throws.
So, Correction is as follows:
List<MappingInstruction> result = emFactory.get()
.createQuery("FROM " + MappingInstruction.class.getSimpleName() + " c where c.mapping = :mapping",
MappingInstruction.class).setParameter("mapping", mappingInfo).getResultList();
Upvotes: 1