java - Hibernate QueryException -
hello trying reference in criteria property of composite key defined , @embeddable on entity
@entity @table(name = "b_j_p") public class bjp implements java.io.serializable { private bjpid id; private bji bji; public bjp() { } public bjp(bjpid id, bji bji) { this.id = id; this.bji = bji; } @embeddedid @attributeoverrides( { @attributeoverride(name = "jiid", column = @column(name = "j_i_id", nullable = false)), @attributeoverride(name = "kn", column = @column(name = "k_n", nullable = false, length = 100)), public bjpid getid() { homecoming this.id; } @manytoone(fetch = fetchtype.lazy) @joincolumn(name = "j_i_id", nullable = false, insertable = false, updatable = false) public bji getbji() { homecoming this.bji; } } i need reach kname following:
@embeddable public class bjpid implements java.io.serializable { private long jiid; private string kname; public bjpid() { } public bjpid(long jiid, string kn) { this.jiid = jiid; this.kn = kn; } @column(name = "j_i_id", nullable = false) public long getjiid() { homecoming this.jiid; } @column(name = "k_name", nullable = false, length = 100) public string getkname() { homecoming this.kname; } } but when trying reach base of operations class bjp property next criteria
detachedcriteria timestampfilter = detachedcriteria.forclass(bjp.class) .createalias("id","alias") .add(restrictions.eq("alias.kname","datasetname")) .setprojection(projections.property("kname")); i next error:
org.hibernate.queryexception: criteria objects cannot created straight on components. create criteria on owning entity , utilize dotted property access component property: id @ org.hibernate.loader.criteria.criteriaquerytranslator.getpathinfo how should formulate criteria query in order reach kname property apply filtering based on in dynamic sql context ?
if have not provided plenty relevant information, please inquire have forgotten provide total context.
edit: upon genzetto advice have managed reach elements(at to the lowest degree not giving errors now) returns no results 1 time this:
detachedcriteria timestampfilter = detachedcriteria.forclass(bjp.class) .add(restrictions.eq("id.kname","datasetname")) .setprojection(projections.property("id.kname")); session currentsession = sessionfactory.getcurrentsession(); criteria query = currentsession.createcriteria(bji.class) .add(subqueries.propertyeq("bjp",timestampfilter)) as upon looking @ sql of format
... this_.j_inst_id = (select this_.k_name y0_ .b_j_p this_ this_.k_name=?) it trying add together subquery id of root object although want part of bjp. how can add together proper location ?
you don't need utilize alias this. can access straight composite key attributes:
detachedcriteria timestampfilter = detachedcriteria.forclass(bjp.class) .add(restrictions.eq("id.kname","datasetname")) .setprojection(projections.property("id.kname")); java sql hibernate criteria
No comments:
Post a Comment