22.2. Hibernate 映射

下列的XML映射应该是很直白的。

  1. <?xml version="1.0"?>
  2. <!DOCTYPE hibernate-mapping PUBLIC
  3. "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  4. "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
  5. <hibernate-mapping package="eg">
  6. <class
  7. name="Blog"
  8. table="BLOGS" >
  9. <id
  10. name="id"
  11. column="BLOG_ID">
  12. <generator class="native"/>
  13. </id>
  14. <property
  15. name="name"
  16. column="NAME"
  17. not-null="true"
  18. unique="true"/>
  19. <bag
  20. name="items"
  21. inverse="true"
  22. order-by="DATE_TIME"
  23. cascade="all">
  24. <key column="BLOG_ID"/>
  25. <one-to-many class="BlogItem"/>
  26. </bag>
  27. </class>
  28. </hibernate-mapping>
  1. <?xml version="1.0"?>
  2. <!DOCTYPE hibernate-mapping PUBLIC
  3. "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  4. "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
  5. <hibernate-mapping package="eg">
  6. <class
  7. name="BlogItem"
  8. table="BLOG_ITEMS"
  9. dynamic-update="true">
  10. <id
  11. name="id"
  12. column="BLOG_ITEM_ID">
  13. <generator class="native"/>
  14. </id>
  15. <property
  16. name="title"
  17. column="TITLE"
  18. not-null="true"/>
  19. <property
  20. name="text"
  21. column="TEXT"
  22. not-null="true"/>
  23. <property
  24. name="datetime"
  25. column="DATE_TIME"
  26. not-null="true"/>
  27. <many-to-one
  28. name="blog"
  29. column="BLOG_ID"
  30. not-null="true"/>
  31. </class>
  32. </hibernate-mapping>