projection - Hibernate 5 required compatible constructor for selected fields -


i upgrade application hibernate 3 hibernate 5.2.10. hibernate's criteria has been deprecated modify code use jpa criteria.

the problem hibernate require specific constructor in dto object selected fields. in hibernate 3 empty constructor + getter/setter enough map results dto while using projection , setresulttransformer(new aliastobeanresulttransformer(mydto.class)).

    criteriabuilder builder = getentitymanager().getcriteriabuilder();     criteriaquery<mydto> criteria = builder.createquery(mydto.class);     root<myentity> root = criteria.from(myentity.class);     criteria.multiselect(root.get(myentity_.id).get(myentityid_.fieldtoselect));     return getentitymanager().createquery(criteria).getresultlist(); 

i got exception :

java.lang.illegalargumentexception: org.hibernate.hql.internal.ast.querysyntaxexception: unable locate appropriate constructor on class [mydtodto]. expected arguments are: java.lang.string [select new mydtodto(generatedalias0.fieldtoselect) myentity generatedalias0] 

according javadoc, normal :

if type of criteria query criteriaquery user-defined class x (i.e., criteria query object created passing x class argument createquery method), elements of list passed multiselect method passed x constructor , instance of type x returned each row.

same problem if use

criteria.select(builder.construct(mydto.class, field1,.., fieldn) 

do have idea avoid creating compatible constructor ? dto used different query dont want create different constructor different query.

thank you


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -