hibernate3学习笔记(十六)|容器映射 - 编程入门网
作者 佚名技术
来源 NET编程
浏览
发布时间 2012-06-19
ersion="1.0" encoding="utf-8"?>2.<!DOCTYPE hibernate-mapping3. PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"4. "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
5.
6.<hibernate-mapping>7.8. <class name="com.hb3.pack_12.model.User" table="user">9.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. <idbag name="items" table="item">17. <collection-id column="cid" type="java.lang.String">
18. <generator class="uuid.hex"/>
19. </collection-id>
20. <key column="id"/>21. <element column="name" type="java.lang.String"/>22. </idbag>
23.24. </class>
25.26.</hibernate-mapping>
hibernate3学习笔记(十六)|容器映射(8)时间:2011-02-03 csdn博客 沈斌测试代码: 1.package com.hb3.pack_13;2.3.import java.io.IOException;4.import java.sql.SQLException;5.import java.util.ArrayList;6. 7.import org.hibernate.Session;8.import org.hibernate.SessionFactory;9.import org.hibernate.Transaction;10.import org.hibernate.cfg.Configuration;11. 12.import com.hb3.pack_12.model.User;13. 14.public class BusinessService {15. 16. public static void main(String[] args) throws IOException, SQLException {17.18. Configuration config = new Configuration().configure();19. SessionFactory sessionFactory = config.buildSessionFactory();20. Session session = sessionFactory.openSession();21.22.23. User user1 = new User();24. user1.setItems(new ArrayList<String>());25. user1.setName("shenbin");26. user1.addItem("Java Gossip");27. user1.addItem("Java Gossip");28. user1.addItem("Caxxx A80");29.30. User user2 = new User();31. user2.setItems(new ArrayList<String>());32. user2.setName("chenyan");33. user2.addItem("Snoppy world");34.35. Transaction tx = session.beginTransaction();36. session.save(user1);37. session.save(user2);38. tx.commit();39. 40.41. session.close();42. session = sessionFactory.openSession();43.44.45. tx = session.beginTransaction();46. User user = (User) session.load(User.class, new Integer(1));47. user.removeItem("Java Gossip");48. tx.commit();49.50.51.52. session.close();53. sessionFactory.close();54. }55.} hibernate3学习笔记(十六)|容器映射(9)时间:2011-02-03 csdn博客 沈斌SQL文的Log: 13:32:16,187 WARN ConfigurationFactory:127 - No configurati |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
关于hibernate3学习笔记(十六)|容器映射 - 编程入门网的所有评论