急求解答ssh问题(多对多)
Configuration cfg = new Configuration().configure();
Session session = cfg.buildSessionFactory().openSession();
Query query = session.createQuery("from SysUser s where s.userName='admin'");
此方法可以得到SysUser方的数据和关联的另一方数据
当在ssh下List list=(List)getHibernateTemplate().find(" from SysUser where userName='amdin'");
只能得到SysUser的数据但是得不到关联的另一方的数据
配置文件如下SysUser:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.1
http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->
<class
name="com.lingxun.hibernate.SysUser"
table="sys_user"
>
<meta attribute="class-description" inherit="false">
@hibernate.class
table="sys_user"
</meta>
<meta attribute="implement-equals" inherit="false">true</meta>
<id
name="id"
type="java.lang.Integer"
column="id"
>
<meta attribute="field-description">
@hibernate.id
generator-class="native"
type="java.lang.Integer"
column="id"
</meta>
<meta attribute="use-in-equals">true</meta>
<generator class="native" />
</id>
<property
name="userName"
type="java.lang.String"
column="user_name"
not-null="true"
unique="true"
length="20"
>
<meta attribute="use-in-tostring">true</meta>
<meta attribute="use-in-equals">true</meta>
<meta attribute="field-description">
@hibernate.property
column="user_name"
unique="true"
length="20"
not-null="true"
</meta>
</property>
<property
name="realName"
type="java.lang.String"
column="real_name"
not-null="false"
length="20"
>
<meta attribute="use-in-tostring">true</meta>
<meta attribute="use-in-equals">true</meta>
<meta attribute="field-description">
@hibernate.property
column="real_name"
length="20"
not-null="true"
</meta>
</property>
<property
name="phone"
type="java.lang.String"
column="phone"
not-null="true"
length="20"
>
<meta attribute="use-in-tostring">true</meta>
<meta attribute="use-in-equals">true</meta>
<meta attribute="field-description">
@hibernate.property
column="phone"
length="20"
not-null="true"
</meta>
</property>
<!-- <property
name="deptId"
type="java.lang.Integer"
column="dept_id"
length="10"
>
<meta attribute="use-in-tostring">true</meta>
<meta attribute="use-in-equals">true</meta>
<meta attribute="field-description">
@hibernate.property
column="dept_id"
length="10"
</meta>
</property>
<property
name="deptName"
type="java.lang.String"
column="dept_name"
length="50"
>
<meta attribute="use-in-tostring">true</meta>
<meta attribute="use-in-equals">true</meta>
<meta attribute="field-description">
@hibernate.property
column="dept_name"
length="50"
</meta>
</property>-->
<property
name="password"
type="java.lang.String"
column="password"
not-null="true"
length="64"
>
<meta attribute="use-in-tostring">true</meta>
<meta attribute="use-in-equals">true</meta>
<meta attribute="field-description">
@hibernate.property
column="password"
length="64"
not-null="true"
</meta>
</property>
<property
name="sex"
type="java.lang.String"
column="sex"
length="2"
>
<meta attribute="use-in-tostring">true</meta>
<meta attribute="use-in-equals">true</meta>
<meta attribute="field-description">
@hibernate.property
column="sex"
length="10"
</meta>
</property>
<property
name="status"
type="java.lang.Integer"
column="status"
length="10"
>
<meta attribute="use-in-tostring">true</meta>
<meta attribute="use-in-equals">true</meta>
<meta attribute="field-description">
@hibernate.property
column="status"
length="10"
</meta>
</property>
<property
name="createTime"
type="java.util.Date"
column="create_time"
not-null="true"
length="19"
>
<meta attribute="use-in-tostring">true</meta>
<meta attribute="use-in-equals">true</meta>
<meta attribute="field-description">
@hibernate.property
column="create_time"
length="19"
not-null="true"
</meta>
</property>
<set name="roles" table="sys_user_role" lazy="false" cascade="all" fetch="select">
<key column="user_id"/>
<many-to-many class="com.lingxun.hibernate.SysRole" column="role_id" />
</set>
<!-- Associations -->
</class>
</hibernate-mapping>
SysRole:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="com.lingxun.hibernate.SysRole" table="sys_role">
<id name="id" type="java.lang.Integer">
<column name="ID" />
<generator class="native"></generator>
</id>
<property name="name" type="java.lang.String">
<column name="ROLE_NAME" length="50" not-null="true" />
</property>
<set name="users" table="sys_user_role" lazy="false">
<key column="role_id"/>
<many-to-many class="com.lingxun.hibernate.SysUser" column="user_id"/>
</set>
</class>
</hibernate-mapping>
如果哪位高手知道,请指教下,感激不尽,并给高分!
[解决办法]
拿set 里的值
[解决办法]
现在流行JAVA呀,这论坛火的
[解决办法]
拿set的值
[解决办法]