ExPosts.hbm.xml 中的一段
----------------------------
<set name="categorys" table="ex_post2cat" lazy="false" inverse="false" cascade="save-update">
<key column="POST_ID"/>
<many-to-many class="dao.org.oneboy.model.ExCategories" column="CATEGORY_ID" outer-join="auto"/>
</set>
----------------------------ExCategories.hbm.xml 中的一段
-----------------------------
<set name="posts" table="ex_post2cat" inverse="true" cascade="save-update" lazy="true">
<key column="CATEGORY_ID"/>
<many-to-many class="dao.org.oneboy.model.ExPosts" column="POST_ID"/>
</set>
-----------------------------ExPost2cat.hbm.xml
-----------------------------
<class name="dao.org.oneboy.model.ExPost2cat" table="ex_post2cat">
<id name="id" type="java.lang.Integer">
<column name="ID"/>
<generator class="native"/>
</id>
<property name="postId" type="java.lang.Integer">
<column name="POST_ID"/>
</property>
<property name="categoryId" type="java.lang.Integer">
<column name="CATEGORY_ID"/>
</property>
</class>
-----------------------------
----------------------------
<set name="categorys" table="ex_post2cat" lazy="false" inverse="false" cascade="save-update">
<key column="POST_ID"/>
<many-to-many class="dao.org.oneboy.model.ExCategories" column="CATEGORY_ID" outer-join="auto"/>
</set>
----------------------------ExCategories.hbm.xml 中的一段
-----------------------------
<set name="posts" table="ex_post2cat" inverse="true" cascade="save-update" lazy="true">
<key column="CATEGORY_ID"/>
<many-to-many class="dao.org.oneboy.model.ExPosts" column="POST_ID"/>
</set>
-----------------------------ExPost2cat.hbm.xml
-----------------------------
<class name="dao.org.oneboy.model.ExPost2cat" table="ex_post2cat">
<id name="id" type="java.lang.Integer">
<column name="ID"/>
<generator class="native"/>
</id>
<property name="postId" type="java.lang.Integer">
<column name="POST_ID"/>
</property>
<property name="categoryId" type="java.lang.Integer">
<column name="CATEGORY_ID"/>
</property>
</class>
-----------------------------
解决方案 »
- 求助:静态变量问题
- 查询数据据库返回到LinkedList 怎么只返回最后一条呢?
- 一个有关EJB3.0中获取JNDI名的问题
- 用struts报错,不知道是什么意思
- struts高人指点下拉列表问题
- 我的验证码图片在TOMCAT下面能正常显示出来,为什么在weblogic8.1下面就显示不出来呢,高手帮忙啊!郁闷啊!!!!!!!!!!!!!!
- hibernate删除问题,简单得很,帮个忙
- 请问关于struts的问题
- weblogic7.0 配置问题?
- 求救!从sql数据库调出数据并转化为xml的程序!!!!
- 如何把IE地址栏中最左边的Tomcat的图标更换成自己的图标?
- 用过Spring的请进来,一个DI的问题
在ExPosts.hbm.xml中:
<set name="categorys"
table="ex_post2cat"
cascade="all"
lazy="true"
inverse="true">
<key column="POST_ID"/>
<many-to-many class="dao.org.oneboy.model.ExCategories"
column="CATEGORY_ID"/>
</set>
在ExCategories.hbm.xml中:
<set name="posts"
table="ex_post2cat"
cascade="all"
lazy="true"
inverse="true">
<key column="CATEGORY_ID"/>
<many-to-many class="dao.org.oneboy.model.ExPosts"
column="POST_ID"/>
</set>另外,你的ex_post2cat关联表中不要设置主键id了,它只需要两个字段用来关联即可。
查询改为:
Query query = session.createQuery("select posts from ExPosts posts left join fetch posts.categorys category where categorys.id=" + id);
query.setFirstResult(start);
query.setMaxResults(pagesize);
return query.list();