composite-id(三)

 

第三 dao增加public List findByIds( SkillTableKey key)<o:p></o:p>

通过SkillTableKey 作为 papm获取<o:p></o:p>

package com.sunnyever.dao;<o:p></o:p>

<o:p> </o:p>

import java.util.List;<o:p></o:p>

<o:p> </o:p>

import com.sunnyever.dao.Dao;<o:p></o:p>

import com.sunnyever.model.SkillTable;<o:p></o:p>

import com.sunnyever.model.SkillTableKey;<o:p></o:p>

<o:p> </o:p>

public interface SkillTableDao extends Dao {<o:p></o:p>

<o:p> </o:p>

    /**<o:p></o:p>

     * Retrieves all of the skillTables<o:p></o:p>

     */<o:p></o:p>

    public List getSkillTables(SkillTable skillTable);<o:p></o:p>

<o:p> </o:p>

    /**<o:p></o:p>

     *find only staff's all skills<o:p></o:p>

     * <o:p></o:p>

     * SkillTableKey is a papm that is  the skillTable's foregin key<o:p></o:p>

     * @return skillTable populated skillTable object<o:p></o:p>

     */<o:p></o:p>

    public List findByIds( SkillTableKey key);<o:p></o:p>

}<o:p></o:p>

第四在class SkillTableDaoHibernate 中实现List findByIds( SkillTableKey key);<o:p></o:p>

<o:p> </o:p>

package com.sunnyever.dao.hibernate;<o:p></o:p>

<o:p> </o:p>

import java.util.List;<o:p></o:p>

<o:p> </o:p>

import com.sunnyever.dao.hibernate.BaseDaoHibernate;<o:p></o:p>

import com.sunnyever.model.SkillTable;<o:p></o:p>

import com.sunnyever.model.SkillTableKey;<o:p></o:p>

import com.sunnyever.dao.SkillTableDao;<o:p></o:p>

<o:p> </o:p>

import org.hibernate.Query;<o:p></o:p>

import org.springframework.orm.ObjectRetrievalFailureException;<o:p></o:p>

<o:p> </o:p>

public class SkillTableDaoHibernate extends BaseDaoHibernate implements SkillTableDao {<o:p></o:p>

<o:p> </o:p>

    /**<o:p></o:p>

     * @see com.sunnyever.dao.SkillTableDao#getSkillTables(com.sunnyever.model.SkillTable)<o:p></o:p>

     */<o:p></o:p>

    public List getSkillTables(final SkillTable skillTable) {<o:p></o:p>

        return getHibernateTemplate().find("from SkillTable");<o:p></o:p>

<o:p> </o:p>

        /* Remove the line above and uncomment this code block if you want <o:p></o:p>

           to use Hibernate's Query by Example API.<o:p></o:p>

        if (skillTable == null) {<o:p></o:p>

            return getHibernateTemplate().find("from SkillTable");<o:p></o:p>

        } else {<o:p></o:p>

            // filter on properties set in the skillTable<o:p></o:p>

            HibernateCallback callback = new HibernateCallback() {<o:p></o:p>

                public Object doInHibernate(Session session) throws HibernateException {<o:p></o:p>

                    Example ex = Example.create(skillTable).ignoreCase().enableLike(MatchMode.ANYWHERE);<o:p></o:p>

                    return session.createCriteria(SkillTable.class).add(ex).list();<o:p></o:p>

                }<o:p></o:p>

            };<o:p></o:p>

            return (List) getHibernateTemplate().execute(callback);<o:p></o:p>

        }*/<o:p></o:p>

    }<o:p></o:p>

<o:p> </o:p>

    /**<o:p></o:p>

     * @see com.sunnyever.dao.SkillTableDao#getSkillTable(long staffskillId)<o:p></o:p>

     */<o:p></o:p>

    public List findByIds( SkillTableKey key) {<o:p></o:p>

        log.debug("getting SkillTable instance with id: " + key);<o:p></o:p>

        try {<o:p></o:p>

           <o:p></o:p>

           <o:p></o:p>

            String hql="from SkillTable m where m.id.staffId=:staffId ";<o:p></o:p>

            Query query= getSession().createQuery(hql);<o:p></o:p>

            query.setProperties(key);<o:p></o:p>

            <o:p></o:p>

            return query.list();<o:p></o:p>

        } catch (RuntimeException re) {<o:p></o:p>

            log.error("get failed", re);<o:p></o:p>

            throw re;<o:p></o:p>

        }<o:p></o:p>

        <o:p></o:p>

    }<o:p></o:p>

    <o:p></o:p>

}<o:p></o:p>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值