Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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...

like image 792
Oscar Avatar asked Nov 25 '25 18:11

Oscar


1 Answers

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"));
like image 145
Naveen Ramawat Avatar answered Nov 28 '25 06:11

Naveen Ramawat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!