hibernate3学习笔记(十九)|关系映射:一对一 - 编程入门网
作者 佚名技术
来源 NET编程
浏览
发布时间 2012-06-19
hibernate3学习笔记(十九)|关系映射:一对一时间:2011-02-03A.唯一外键关联 DDL: 1.CREATE TABLE user (2. id INT(11) NOT NULL auto_increment PRIMARY KEY,3. name VARCHAR(100) NOT NULL default '''',4. room_id INT(11)5.);6.7.CREATE TABLE room (8. id INT(11) NOT NULL auto_increment PRIMARY KEY,9. address VARCHAR(100) NOT NULL default ''''10.); User.java 1.package com.hb3.pack_02.model;2.3.public class User {4. 5. private Integer id;6. private String name;7. private Room room;8.9. public User() {10. }11. 12. public Integer getId() {13. return id;14. }15. public void setId(Integer id) {16. this.id = id;17. }18. public String getName() {19. return name;20. }21. public void setName(String name) {22. this.name = name;23. }24. public Room getRoom() {25. return room;26. }27. public void setRoom(Room room) {28. this.room = room;29. }30.} hibernate3学习笔记(十九)|关系映射:一对一(2)时间:2011-02-03Room.java 1.package com.hb3.pack_02.model;2.3.public class Room {4. 5. private Integer id;6. private String address;7. private User user;8.9. public Room() {10. }11.12. public Integer getId() {13. return id;14. }15. public void setId(Integer id) {16. this.id = id;17. }18. public String getAddress() {19. return address;20. }21. public void setAddress(String address) {22. this.address = address;23. }24. public User getUser() {25. return user;26. }27. public void setUser(User user) {28. this.user = user;29. }30.} User.hbm.xml 1.<?xml version="1.0" encoding="UTF-8"?>2. 3.<!DOCTYPE hibernate-mapping PUBLIC4. "-//Hibernate/Hibernate Mapping DTD 3.0//EN"5. "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> 6. 7.<hibernate-mapping>8. 9. <class name="com.hb3.pack_02.model.User" table="user">10. <id name="id" column="id" type="java.lang.Integer">11. <generator class="native"/>12. </id>13.14. <property name="name" column="name" type="java.lang.String"/>15.16. <many-to-one name="room"17. column="room_id"18. class="com.hb3.pack_02.model.Room" 19. cascade="all" 20. outer-join="true" 21. unique="true"/>22. </class>23. 24.</hibernate-mapping> hibernate3学习笔记(十九)|关系映射:一对一(3)时间:2011-02-03Room.hbm.xml 1.<?xml version="1.0" encoding="UTF-8"?>2. 3.<!DOCTYPE hibernate-mapping PUBLIC4. "-//Hibernate/Hibernate Mapping DTD 3.0//EN"5. "http://hibernate.sourceforge.n |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
关于hibernate3学习笔记(十九)|关系映射:一对一 - 编程入门网的所有评论