hibernate 多对一映射 many-to-one
来源:互联网 发布:433m模块stc单片机解码 编辑:程序博客网 时间:2024/05/16 12:48
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="cn.pgh.orm">
<class name="Employee">
<id name="id">
<generator class="native"/>
</id>
<property name="name" length="10" not-null="true"/>
<many-to-one name="dept" column="dept_id"></many-to-one>
</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">
<hibernate-mapping package="cn.pgh.orm">
<class name="Department">
<id name="id">
<generator class="native"/>
</id>
<property name="name" length="10" not-null="true"/>
</class>
</hibernate-mapping>
package cn.pgh.action;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import cn.pgh.orm.Department;
import cn.pgh.orm.Employee;
public class ManyToOne {
public static void main(String args[])
{
add();
}
static Department add()
{
Department dept=new Department();
Employee em=new Employee();
Session s=null;
Transaction tx=null;
try
{
s=HibernateUtil.getSession();
tx=s.beginTransaction();
dept.setName("技术部");
em.setDept(dept);
em.setName("凌波丽");
s.save(dept);
s.save(em);
tx.commit();
}
catch(HibernateException e)
{
if(tx!=null)
{
tx.rollback();
}
throw e;
}
finally
{
if(s!=null)
{
s.close();
}
}
return dept;
}
}
- hibernate 多对一映射 many-to-one
- Hibernate关联映射(多对一 --- many-to-one)
- Hibernate 多对一(Many-to-One)映射
- Hibernate 、多表关联映射-多对一关系(many-to-one)
- hibernate 双向多对一 many-to-one 映射 关联查询
- hibernate单向多对一关联映射(many-to-one)XML与注解版
- hibernate 多对一(Many-to-one)单向关联
- Hibernate one-to-many / many-to-one关系映射
- Hibernate one-to-many / many-to-one关系映射
- 多对一(many-to-one)
- 多对一(many-to-one) .
- 多对一(many-to-one)
- Hibernate one-to-many && many-to-many 的关系映射
- hibernate annotation many-to-one cascade 没用(Hibernate 注解 多对一 级联 没用)
- hibernate映射技巧one-to-many(单项一对多)
- hibernate映射技巧one-to-many(双向一对多)
- hibernate映射技巧one-to-many(单项一对多)
- Hibernate One-to-Many Mappings 一对多关系映射
- C语言中如何使用宏 包括单双井号 可变参数
- python_udp数据报传输的实现
- win7 32 安装oracle server 10.2.0.1.0
- s3c2440定时器简介
- 使用jQuery实现鼠标悬浮图片轮换效果
- hibernate 多对一映射 many-to-one
- nginx location的管理以及查找
- objective 消息中心的处理
- python时间函数
- 移动视频分享应用Klip获Benchmark领投800万B轮融资
- vim自动补全功能
- 找出两个已经排好序的数组的中位数
- hibernate criteria查询
- C#Socket 通信