首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

Hibernate回到一个实体

2012-07-05 
Hibernate返回一个实体@Overridepublic ExistedSystem getExistedSystemByName(String existedSystemName)

Hibernate返回一个实体
@Override
    public ExistedSystem getExistedSystemByName(String existedSystemName)
    {
        String hql = "select * from tbl_existed_system where name = {0}";
        final String formathql = MessageFormat.format(hql, "'" + existedSystemName + "'");
        ExistedSystem ret = (ExistedSystem)getHibernateTemplate().executeWithNewSession(new HibernateCallback()
        {
           
            @Override
            public Object doInHibernate(Session session)
                throws SQLException
            {
                ExistedSystem existedSystem = new ExistedSystem();
                Object[] next = (Object[])session.createSQLQuery(formathql).uniqueResult();
                Project project = new Project();
                project.setProjectId((Integer)next[0]);
                existedSystem.setProject(project);
                existedSystem.setServerId((Integer)next[1]);
               
                existedSystem.setName(next[Constants.TWO].toString());
                existedSystem.setDescription(next[Constants.THREE].toString());
                existedSystem.setModel(next[Constants.FOUR].toString());
                existedSystem.setProcessorFamily(next[Constants.FIVE].toString());
                existedSystem.setCpuCores((Short)next[Constants.SIX]);
                existedSystem.setCpuCoreSpeed((Short)next[Constants.SEVEN]);
                existedSystem.setMemoryCapacity((Float)next[Constants.EIGHT]);
                existedSystem.setDiskIoCapacity((Float)next[Constants.NINE]);
                existedSystem.setNetworkIoCapacity((Float)next[Constants.TEN]);
                existedSystem.setOs(next[Constants.ELEVEN].toString());
                existedSystem.setType((Short)next[Constants.TWELVE]);
                return existedSystem;
            }
        });
       
        return ret;
    }
   
    /** {@inheritDoc} */

热点排行