hibernate many-to-one list 映射问题 在线等 可加分
publicclassCompany{privateIntegerid;privateStringcompayName;privateList<Organization>...
public class Company
{
private Integer id;
private String compayName;
private List<Organization> organization;
} //getter,setter 略
————————————————
public class Organization
{
private Integer id;
private String orgName;
} //getter,setter 略
Company 与 Organization 关系是多对一 请问如何写 hbm.xml 配置文件 展开
{
private Integer id;
private String compayName;
private List<Organization> organization;
} //getter,setter 略
————————————————
public class Organization
{
private Integer id;
private String orgName;
} //getter,setter 略
Company 与 Organization 关系是多对一 请问如何写 hbm.xml 配置文件 展开
展开全部
<?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="类路径" table="表名" lazy="false">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="native" />
</id>
<many-to-one name="Organization" class="这里写类的位置Organization" fetch="select">
<column name="id" not-null="true" />
</many-to-one>
<property name="Organization" type="java.lang.String">
<column name="Organization" length="500" />
</property>
</class>
</hibernate-mapping>
---------------------------------------------------------------------------------------------------------
<?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="这里写类的位置Company" table="表名" lazy="false">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="native" />
</id>
<property name="compayNmae" type="java.lang.String">
<column name="compayNmae" length="10" not-null="true" />
</property>
<set name="organization" lazy="false" inverse="true">
<key>
<column name="关联ID" not-null="true" />
</key>
<one-to-many class="ComPany类路径" />
</set>
</class>
</hibernate-mapping>
又不懂的地方你在发出来或者加我也行719317913 希望能解决您的问题
<!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="类路径" table="表名" lazy="false">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="native" />
</id>
<many-to-one name="Organization" class="这里写类的位置Organization" fetch="select">
<column name="id" not-null="true" />
</many-to-one>
<property name="Organization" type="java.lang.String">
<column name="Organization" length="500" />
</property>
</class>
</hibernate-mapping>
---------------------------------------------------------------------------------------------------------
<?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="这里写类的位置Company" table="表名" lazy="false">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="native" />
</id>
<property name="compayNmae" type="java.lang.String">
<column name="compayNmae" length="10" not-null="true" />
</property>
<set name="organization" lazy="false" inverse="true">
<key>
<column name="关联ID" not-null="true" />
</key>
<one-to-many class="ComPany类路径" />
</set>
</class>
</hibernate-mapping>
又不懂的地方你在发出来或者加我也行719317913 希望能解决您的问题
大雅新科技有限公司
2024-11-19 广告
2024-11-19 广告
这方面更多更全面的信息其实可以找下大雅新。深圳市大雅新科技有限公司从事KVM延长器,DVI延长器,USB延长器,键盘鼠标延长器,双绞线视频传输器,VGA视频双绞线传输器,VGA延长器,VGA视频延长器,DVI KVM 切换器等,优质供应商,...
点击进入详情页
本回答由大雅新科技有限公司提供
展开全部
多对一需要一个外键
按你的程序应该是:1个company 含 多个Organization
Organization 需要有一个companyId字段,
同时定义一个company属性 private Company company;//getter,setter
<many-to-one name="company"
class="Organization "
cascade="none"
outer-join="auto"
update="false"
insert="false"
not-null="false"
column="COMPANY_ID" />
按你的程序应该是:1个company 含 多个Organization
Organization 需要有一个companyId字段,
同时定义一个company属性 private Company company;//getter,setter
<many-to-one name="company"
class="Organization "
cascade="none"
outer-join="auto"
update="false"
insert="false"
not-null="false"
column="COMPANY_ID" />
追问
不是啊 是 多个 Company 映射一个 Organization 因此而纠结··· 不然在 Organization 里设个Set 就完事了··· 主要是不能改代码
追答
那company类就不能是private List organization;
而应该改成private Organization organization;
代码就是错的,不能改代码?那要怎么做啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询