I have an entity which has composite primary key. So i created primary class for the entity class with @EmbeddedId
annotation.
I need help. While fetching that entity, is it possible to fetch the one of the primary key?
I tried to pass one of primary key to fetch that entity, other primary keys are set to zero and no result obtained.
Is there any way to fetch an entity (which has composite primary key) by specifying one of the primary key for that entity?
Sample code:
EmbeddedRiskDetailPK riskDetailPK = new EmbeddedRiskDetailPK ();
riskDetailPK.setRiskId(riskId);
Criteria criteria = hibernateDBSession.createCriteria(RiskDetail.class, "riskDetail")
.add(Restrictions.eq("riskDetail.embeddedRiskDetailPK ",riskDetailPK ));
isRecordCount = criteria.uniqueResult() != null ? ((Number)criteria.uniqueResult()).longValue() : 0;