List<UserFunction> resultList = (List<UserFunction>) getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session session) throws HibernateException, SQLException {
SQLQuery query = session.createSQLQuery(sql);
query.setResultTransformer(Transformers.aliasToBean(UserFunction.class)); //映射到UserFunction类
query.setInteger(0, 1);
return query.list();
}});
//一对一
//详细表
<id name="PId" type="java.lang.Integer">
<column name="p_id" />
<generator class="foreign" >
<param name="property">tsWallpaperProducts </param>
</generator>
</id>
<one-to-one name="tsWallpaperProducts " class="com.topsoft.admin.bean.TsWallpaperProduct" constrained="true" lazy="proxy"></one-to-one>
//显示列表
<one-to-one name="tsWallpaperDetail" class="com.topsoft.admin.bean.TsWallpaperDetail" constrained="true" lazy="proxy"></one-to-one>
//关系表
//产品表
<set name="tsWallpaperCategoryRelationshipses" inverse="true">
<key>
<column name="object_id" not-null="true" />
</key>
<one-to-many class="com.topsoft.admin.bean.TsWallpaperCategoryRelationships" />
</set>
//类别关系表
<hibernate-mapping>
<class name="com.topsoft.admin.bean.TsWallpaperCategoryRelationships" table="TS_Wallpaper_Category_Relationships">
<composite-id name="wid" class="com.topsoft.admin.bean.TsWallpaperCategoryRelationshipsId">
<key-many-to-one name="tsWallpaperProduct" class="com.topsoft.admin.bean.TsWallpaperProduct">
<column name="object_id" />
</key-many-to-one>
<key-many-to-one name="tsWallpaperCategoryTaxonomy" class="com.topsoft.admin.bean.TsWallpaperCategoryTaxonomy">
<column name="ct_id" />
</key-many-to-one>
</composite-id>
<property name="crId" type="java.lang.Integer" insert="false" update="false">
<column name="cr_id" not-null="true" />
</property>
<property name="crOrder" type="java.lang.Integer">
<column name="cr_order" />
</property>
</class>
</hibernate-mapping>
//类别表
<hibernate-mapping>
<class name="com.topsoft.admin.bean.TsWallpaperCategoryTaxonomy" table="TS_Wallpaper_Category_Taxonomy">
<id name="ctId" type="java.lang.Integer">
<column name="ct_id" />
<generator class="native" />
</id>
<property name="ctName" type="java.lang.String">
<column name="ct_name" length="700" />
</property>
<property name="ctNickName" type="java.lang.String">
<column name="ct_nick_name" length="700" />
</property>
<property name="ctLink" type="java.lang.String">
<column name="ct_link" length="500" />
</property>
<property name="ctImg" type="java.lang.String">
<column name="ct_img" length="1000" />
</property>
<property name="ctTaxonomy" type="java.lang.String">
<column name="ct_taxonomy" length="300" />
</property>
<property name="ctDescription" type="java.lang.String">
<column name="ct_description" length="500" />
</property>
<property name="ctParent" type="java.lang.Integer">
<column name="ct_parent" />
</property>
<property name="ctGroup" type="java.lang.Integer">
<column name="ct_group" />
</property>
</class>
</hibernate-mapping>
//添加产品
@SuppressWarnings("unchecked")
public String addWallpaper(){
//wallpaper + wallpaper detail
getEntity().setPAddTime(new Date());
getEntity().setPReleaseTime(new Date());
getEntity().setPUpdateTime(new Date());
Document descXmlStr = getDescXml(getEntity());
wallpaperDetail = new TsWallpaperDetail();
wallpaperDetail.setPDescribe(descXmlStr.asXML());
wallpaperDetail.setPPageInfo(getPageInfoXml(getEntity()).asXML());
wallpaperDetail.setPLink(getLinkXml(getEntity()).asXML());
wallpaperDetail.setPDownloadLink(getDownloadLinkXml(getEntity()).asXML());
wallpaperDetail.setPBuyLink(getBuyLinkXml(getEntity()).asXML());
wallpaperDetail.setPOtherLinks(getOtherLinkXml(getEntity()).asXML());
wallpaperDetail.setPImg("");
wallpaperDetail.setPFeaturedCount(0);
//设置产品和产品详细之间的关系
getEntity().setTsWallpaperDetail(wallpaperDetail);
wallpaperDetail.setTsWallpaperProducts(getEntity());
//插入关键字
getEntity().getTsWallpaperKeywords().add(wallpaperKeyword);
//插入产品
getService().insert(getEntity());
//插入详细
wallpaperDetailService.insert(wallpaperDetail);
TsWallpaperCategoryRelationshipsId id = new TsWallpaperCategoryRelationshipsId();
TsWallpaperCategoryRelationships wr = new TsWallpaperCategoryRelationships();
//添加类别
TsWallpaperCategoryTaxonomy category = wallpaperCategoryTaxonomyService.get(wallpaperCategoryTaxonomy.getCtId());
id.setTsWallpaperCategoryTaxonomy(category);
//添加产品
id.setTsWallpaperProduct(getEntity());
//分类表设置
wr.setWid(id);
//分组设置
wr.setCrOrder(1);
//插入类别
wallpaperCategoryRelationshipService.insert(wr);
return SUCCESS;
}