-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Mapped entity returned as null when row exists in DB
PostPosted: Fri Oct 14, 2016 1:34 pm 
Beginner
Beginner

Joined: Wed Mar 03, 2010 3:35 pm
Posts: 37
Hi,
I am struggling with below issue where an User entity exists in db by the searched userLoginId, but below code always returns null,
the database is mariaDB (10.2.2 alpha version) and Hibernate core version is 4.2, mariadb-java-driver 1.5.3.
The dialect used is org.hibernate.dialect.MySQL5InnoDBDialect



String queryStr = "from User t where t.userLoginId = :userLoginId";


User user = null;
List<User> result = null;
try{
Query query = getSession().createQuery(queryStr);
query.setParameter("userLoginId", userLoginId);
result = query.list();
} catch(Exception e){}


the result is always null, I checked for a couple of different existing ID's, but the same.

I copied the generated SQL statement as below from the logs and executed from a sql client , I get a row returned there for below 3 sql'sm.
The first select is the main User entity mapped to user table, and next 2 selects are many to one mappings to person table.

1)
Hibernate: select user0_.USR_ID as USR_ID1_55_, user0_.UPD_TS as UPD_TS2_55_, user0_.USR_PSWD1 as USR_PSWD3_55_, user0_.USR_STA_CD as USR_STA_4_55_, user0_.USR_LOGIN_ID as USR_LOGI5_55_, user0_.LAST_LOGIN_TS as LAST_LOG6_55_, user0_.EXPIRN_DT as EXPIRN_D7_55_, user0_.ACTVTN_DT as ACTVTN_D8_55_, user0_.PLCY_ID as PLCY_ID9_55_, user0_.ACPT_UAL_IND as ACPT_UA10_55_, user0_.NUM_FMT_ID as NUM_FMT11_55_, user0_.DT_FMT_ID as DT_FMT_12_55_, user0_.TM_FMT_ID as TM_FMT_13_55_, user0_.TMZONE_ID as TMZONE_14_55_, user0_.LOCALE_ID as LOCALE_15_55_, user0_.REVSYNC_UPD_ID as REVSYNC16_55_, user0_.STA_CMNT as STA_CMN17_55_, user0_.ACCT_TYP_CD as ACCT_TY18_55_, user0_.FED_MAP as FED_MAP19_55_, user0_.ORG_IDP_ID as ORG_IDP20_55_, user0_.DEX_RSTRCT as DEX_RST21_55_, user0_.USR_TYP_ID as USR_TYP22_55_, user0_.ORG_ID as ORG_ID23_55_, user0_.REGN_ID as REGN_ID24_55_, user0_.USR_UNIQ_ID as USR_UNI25_55_, user0_.PREF_MAX_RSLT_PG as PREF_MA26_55_, user0_.FPS_LCK_OUT_CNT as FPS_LCK27_55_, user0_.DEL_REQST_TS as DEL_REQ28_55_, user0_.USR_SECRY_LVL as USR_SEC29_55_, user0_.PRSN_ID as PRSN_ID30_55_, user0_.MGR_ID as MGR_ID31_55_, user0_.CERT_REQST_STA as CERT_RE32_55_, user0_.CERT_REQST_INFO as CERT_RE33_55_, user0_.APPLN_ADMNR_REGN_TXT as APPLN_A34_55_, user0_.USR_FUNCL_ROLE as USR_FUN35_55_, user0_.USR_ORG_HIER_VAL as USR_ORG36_55_, user0_.HOLD_BUS_TYP as HOLD_BU37_55_, user0_.USR_PRDCT_NM as USR_PRD38_55_, user0_.RELN_TO_VISA_TXT as RELN_TO39_55_, user0_.LANDG_PG_NM as LANDG_P40_55_, user0_.BLC_SECR_HOME_PG_ACCS_IND as BLC_SEC41_55_ from FAC_USR user0_ where user0_.USR_LOGIN_ID=?

2)
Hibernate: select person0_.PRSN_ID as PRSN_ID1_33_2_, person0_.UPD_TS as UPD_TS2_33_2_, person0_.nm_first as nm_first3_33_2_, person0_.nm_last as nm_last4_33_2_, person0_.nm_pre as nm_pre5_33_2_, person0_.nm_mi as nm_mi6_33_2_, person0_.nm_suf as nm_suf7_33_2_, person0_.title as title8_33_2_, person0_.phn_num as phn_num9_33_2_, person0_.phn_ext as phn_ext10_33_2_, person0_.fax as fax11_33_2_, person0_.email as email12_33_2_, person0_.mail_stop as mail_st13_33_2_, person0_.dept as dept14_33_2_, person0_.EMAIL_CNFRMN_IND as EMAIL_C15_33_2_, person0_.addr_id as addr_id16_33_2_, address1_.ADDR_ID as ADDR_ID1_0_0_, address1_.UPD_TS as UPD_TS2_0_0_, address1_.line1 as line3_0_0_, address1_.line2 as line4_0_0_, address1_.line3 as line5_0_0_, address1_.city as city6_0_0_, address1_.state as state7_0_0_, address1_.postal1 as postal8_0_0_, address1_.postal2 as postal9_0_0_, address1_.country as country10_0_0_, 1 as formula4_0_, country2_.CTRY_ID as CTRY_ID1_18_1_, country2_.LOCALE_ID as LOCALE_I2_18_1_, country2_.CTRY_CD as CTRY_CD3_18_1_, country2_.CTRY_DSPLY_NM as CTRY_DSP4_18_1_ from FAC_PRSN person0_ left outer join FAC_ADDR address1_ on person0_.addr_id=address1_.ADDR_ID left outer join FAC_CTRY_I18N country2_ on address1_.country=country2_.CTRY_ID and 1=country2_.LOCALE_ID where person0_.PRSN_ID=?

3)
Hibernate: select person0_.PRSN_ID as PRSN_ID1_33_2_, person0_.UPD_TS as UPD_TS2_33_2_, person0_.nm_first as nm_first3_33_2_, person0_.nm_last as nm_last4_33_2_, person0_.nm_pre as nm_pre5_33_2_, person0_.nm_mi as nm_mi6_33_2_, person0_.nm_suf as nm_suf7_33_2_, person0_.title as title8_33_2_, person0_.phn_num as phn_num9_33_2_, person0_.phn_ext as phn_ext10_33_2_, person0_.fax as fax11_33_2_, person0_.email as email12_33_2_, person0_.mail_stop as mail_st13_33_2_, person0_.dept as dept14_33_2_, person0_.EMAIL_CNFRMN_IND as EMAIL_C15_33_2_, person0_.addr_id as addr_id16_33_2_, address1_.ADDR_ID as ADDR_ID1_0_0_, address1_.UPD_TS as UPD_TS2_0_0_, address1_.line1 as line3_0_0_, address1_.line2 as line4_0_0_, address1_.line3 as line5_0_0_, address1_.city as city6_0_0_, address1_.state as state7_0_0_, address1_.postal1 as postal8_0_0_, address1_.postal2 as postal9_0_0_, address1_.country as country10_0_0_, 1 as formula4_0_, country2_.CTRY_ID as CTRY_ID1_18_1_, country2_.LOCALE_ID as LOCALE_I2_18_1_, country2_.CTRY_CD as CTRY_CD3_18_1_, country2_.CTRY_DSPLY_NM as CTRY_DSP4_18_1_ from FAC_PRSN person0_ left outer join FAC_ADDR address1_ on person0_.addr_id=address1_.ADDR_ID left outer join FAC_CTRY_I18N country2_ on address1_.country=country2_.CTRY_ID and 1=country2_.LOCALE_ID where person0_.PRSN_ID=?



There are some other hibernate criteria queries that do work and return results like the one below,

Criteria parentCriteria = super.getSession().createCriteria(Country.class);
parentCriteria.addOrder(Order.asc("locale"));
parentCriteria.addOrder(Order.asc("name"));
return parentCriteria.list();



Not sure whats causing result to be returned as null. please help.


Top
 Profile  
 
 Post subject: Re: Mapped entity returned as null when row exists in DB
PostPosted: Fri Oct 14, 2016 4:24 pm 
Beginner
Beginner

Joined: Wed Mar 03, 2010 3:35 pm
Posts: 37
data issue was causing this as data migrated from db2 to mariadb was not correct with <null> replaced by just empty strings.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.