java - BETWEEN query with JPA and Metamodel -


i trying write between query jpa 2.

integer zipcode = 50000; criteriabuilder builder = getentitymanager().getcriteriabuilder(); criteriaquery<territory> query = builder.createquery(territory.class); metamodel m = getentitymanager().getmetamodel();  root<territory> root = query.from(territory.class);  // zipcode between startzipcoderange , endzipcoderange predicate condition = builder.between(zipcode , root.get(territory_.startzipcoderange), root.get(territory_.endzipcoderange)); 

the final line not compile because zipcode not of type expression. possible convert zipcode expression? if so, how that.

you can use root.get(territory_.zipcode) 1st parameter of between function if, territory have zipcode attribute.

see comments on answer more details.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -