Oscar
Oscar

Reputation: 31

cannot resolve property when criteria refers to a embedded property

I seem to be unable to create a query with a criterion which refers to a property inside a Embedded class. When i use "entity.embedded.property" it fails. If i create an alias of "entity.embedded.property" to itself the query works...Any tipes will be appreciated...

Upvotes: 3

Views: 3461

Answers (1)

Naveen Ramawat
Naveen Ramawat

Reputation: 61

You could not directly access the properties of embedded object. You should create an alias for it instead. Like

Criteria crit = session.createCriteria(XYZ.class, "entity");
crit.setProjection(Projections.property("id"));
crit.createAlias("entity.embedded", "embeddedObj");
crit.add(Restrictions.eq("embeddedObj.property1", "propert1_value"));

Upvotes: 6

Related Questions