Reputation: 520
I'm currently having an issue using Java JPA with EclipseLink - this query:
SELECT VAR_INPUT.*
FROM VAR_INPUT
INNER JOIN TYPE_VAR_INPUT
ON VAR_INPUT.ID_TYPE_VAR_INPUT = TYPE_VAR_INPUT.ID_TYPE_VAR_INPUT
WHERE TYPE_VAR_INPUT.IS_MANDATORY_TYPE_VAR_INPUT=true;
is working fine when run directly on my database, but doesn't work when I use it with JPA.
JPA Query:
@NamedQuery(name = "VarInput.findAVarInputllOfMandatoryType",
query = "SELECT v "
+ "FROM VarInput v "
+ "INNER JOIN TypeVarInput t "
+ "ON v.ID_TYPE_VAR_INPUT = t.ID_TYPE_VAR_INPUT "
+ "WHERE t.isMandatoryTypeVarInput=:isMandatoryTypeVarInput"),
When I execute it in my Java application, I get the following error: "The field [VAR_INPUT.ID_VAR_INPUT] in this expression has an invalid table in this context."
Exception in thread "AWT-EventQueue-0" Local Exception Stack:
Exception [EclipseLink-6069] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.QueryException
Exception Description: The field [VAR_INPUT.ID_VAR_INPUT] in this expression has an invalid table in this context.
Query: ReadAllQuery(name="VarInput.findAVarInputllOfMandatoryType" referenceClass=VarInput jpql="SELECT v FROM VarInput v INNER JOIN TypeVarInput t ON v.ID_TYPE_VAR_INPUT = t.ID_TYPE_VAR_INPUT WHERE t.isMandatoryTypeVarInput=:isMandatoryTypeVarInput")
at org.eclipse.persistence.exceptions.QueryException.invalidTableForFieldInExpression(QueryException.java:749) at org.eclipse.persistence.exceptions.QueryException.invalidTableForFieldInExpression(QueryException.java:749)
at org.eclipse.persistence.internal.expressions.FieldExpression.validateNode(FieldExpression.java:296)
My tables looks like that:
Table VAR_INPUT(ID_VAR_INPUT, NAME_VAR_INPUT, ID_TYPE_VAR_INPUT)
Table TYPE_VAR_INPUT(ID_TYPE_VAR_INPUT, NAME_TYPE_VAR_INPUT, IS_MANDATORY_VAR_INPUT)
"VAR_INPUT ManyToOne TYPE_VAR_INPUT"
Do you have any idea of why this happens?
NB: The Entities were generated by NetBeans
Upvotes: 2
Views: 1615
Reputation: 24403
You don't use inner join
in JQPL like that, you join on entity fields. I'm guessing now since you didn't provide entity code, but try this
@NamedQuery(name = "VarInput.findAVarInputllOfMandatoryType",
query = "SELECT v "
+ "FROM VarInput v "
+ "join v.type t "
+ "WHERE t.isMandatoryTypeVarInput=:isMandatoryTypeVarInput")
In this case you don't even need to join, you can simplify the query to this (inner join is implicitly used)
@NamedQuery(name = "VarInput.findAVarInputllOfMandatoryType",
query = "SELECT v "
+ "FROM VarInput v "
+ "WHERE v.type.isMandatoryTypeVarInput=:isMandatoryTypeVarInput")
Upvotes: 2