jpa - query with OneToMany - openJPA vs EclipseLink -
openjpa complaining incorrect argument jpa query eclipselink handles. eclipselink returns set of validation messages motor.
two questions:
1) query wrong , eclipselink kindly handling anyway?
2) suggestions on how restructure query openjpa?
thanks thinking question!
query
select m.valmessages threephasemotorinput m m.id = :id
actual openjpa exception
caused by: <openjpa-2.3.0-r422266:1540826 nonfatal user error> org.apache.openjpa.persistence.argumentexception: query projections cannot include array, collection, or map fields. invalid query: "select m.valmessages threephasemotorinput m m.id = :id" @ org.apache.openjpa.kernel.expressionstorequery$abstractexpressionexecutor.assertnotcontainer(expressionstorequery.java:328) @ org.apache.openjpa.kernel.expressionstorequery$datastoreexecutor.<init>(expressionstorequery.java:770) @ org.apache.openjpa.kernel.expressionstorequery.newdatastoreexecutor(expressionstorequery.java:179) @ org.apache.openjpa.kernel.queryimpl.createexecutor(queryimpl.java:749) @ org.apache.openjpa.kernel.queryimpl.compilefordatastore(queryimpl.java:707) @ org.apache.openjpa.kernel.queryimpl.compileforexecutor(queryimpl.java:689) @ org.apache.openjpa.kernel.queryimpl.compile(queryimpl.java:589) @ org.apache.openjpa.persistence.entitymanagerimpl.createnamedquery(entitymanagerimpl.java:1038) @ org.apache.openjpa.persistence.entitymanagerimpl.createnamedquery(entitymanagerimpl.java:1017)
threephasemotorinput mapping
public class threephasemotorinput implements ithreephasemotorinput, serializable { private static final long serialversionuid = 8084370807289186987l; @id @generatedvalue(strategy = generationtype.identity) private long id; @version private integer version; private integer status; @onetoone(cascade = cascadetype.all, optional = true, targetentity = unapprovedthreephasemotor.class) @joincolumn(name = "unapproved_id") private ithreephasemotor unapprovedmotor; @onetoone(cascade = cascadetype.all, optional = true, targetentity = approvedthreephasemotor.class) @joincolumn(name = "approved_id") private ithreephasemotor approvedmotor; @onetomany(orphanremoval = true, cascade = cascadetype.all, fetch = fetchtype.lazy, targetentity = validationmessage.class) @joincolumn(name = "input_id", referencedcolumnname = "id", nullable = false) @ordercolumn(name = "idx") private list<ivalidationmessage> valmessages;
validationmessage mapping
public class validationmessage implements serializable, ivalidationmessage { private static final long serialversionuid = 8765213112015434057l; @id @generatedvalue(strategy = generationtype.identity) private long id; @column(name = "record_id") private long recordid; @column(name = "field_name") private string fieldname; @column(name = "validation_msg") private string validationmsg; private integer status; @column(name = "fail_field") private string failfield; @column(name = "error_source") private integer errorsource;
check http://docs.oracle.com/javaee/6/tutorial/doc/bnbuf.html#bnbvx - select clause: select clause cannot specify collection-valued expression. example, select clause p.teams invalid because teams collection. can use valmessages inner/outer join , select ivalidationmessage entities trough it, e.g.:
select ivm threephasemotorinput tpmi inner join tpmi.valmessages ivm tpmi.id = :id
Comments
Post a Comment