java - Read data from table where primary key is composite using hibernate -
i have these pojo classes in project.
public class merchantchainuser extends com.avanza.ni.common.dto.abstractdto implements java.io.serializable { private long chainid; private compositepk compositepk; public merchantchainuser() { } public void setchainid(long chainid) { this.chainid = chainid; } public long getchainid() { return chainid; } public void setcompositepk(compositepk compositepk) { this.compositepk = compositepk; } public compositepk getcompositepk() { return compositepk; } } , public class compositepk implements serializable { private long merchantid; private long userid; public void setmerchantid(long merchantid) { this.merchantid = merchantid; } public long getmerchantid() { return merchantid; } public void setuserid(long userid) { this.userid = userid; } public long getuserid() { return userid; } }
hbm.xml file merchantuserchain
is
<hibernate-mapping> <class name="com.avanza.ni.portal.dto.merchantchainuser" table="merchant_chain_user"> <composite-id name="compositepk"> <key-property name="merchantid" type="long" column="merchant_id"></key-property> <key-property name="userid" type="long" column="merchant_user_id"></key-property> </composite-id> <property name="chainid" type="long"> <column name="merchant_chain_id" length="38" /> </property> </class>
now wanted have read data table using merchant_user_id
. able retreive whole data table want set criteria only give me row merchant_user_id specific
. didn't know how write data criteria.
the answer put comment has been deleted, post here :d
criteria crit = session.createcriteria(merchantchainuser.class) .add(restrictions.eq("compositepk.userid", userid));
or hql
session.createquery("from merchantchainuser compositepk.userid = :userid").setparameter("userid",userid);
Comments
Post a Comment