java - How to map native query to one model class? -
hi i´m using eclipselink , did native query select fields of 2 tables. mapped table logins in model class. not map table "b" because need 2 fields of table on sql result.. can map 2 fields in logins table sql result ?
my sql this:
select l.login_id, s.lugarcerto,s.vrum, l.username, l.first_name, l.last_name, l.phone, l.fax_number, l.address, l.zip, l.address2 'birth_date', l.city 'cpf_cnpj' logins l join (select se.login_id, lugarcerto = min(case when se.service = 'im' '1' end), vrum = min(case when se.service = 've' '1' end) (select distinct ad.login_id, substring(ap.rate_code,(charindex('-', ap.rate_code)+1),2) 'service' ad_data.dbo.ad ad join ad_data.dbo.ad_pub ap on (ad.ad_id = ap.ad_id) ap.ad_type =1) se group se.login_id) s on (s.login_id = l.login_id) i did map logins table , want map s.lugarcerto , s.vrum sql query result. there´s anyway add logins model ?
not without having mappings attributes want values put into, , not without causing problems them being cached in entity.
why not return values beside entity, jpql query such as: "select l, subquery1, subquery2 logins l" ie:
query q = em.createnativequery(yourquerystring, "resultmappingname"); and in entity, include annotation:
@sqlresultsetmapping(name="resultmappingname", entities={@entityresult(entityclass=com.acme.logins.class, )}, columns={@columnresult(name="lugarcerto"), @columnresult(name="vrum")} ) best regards, chris
Comments
Post a Comment