Raible's Wiki

Raible Designs
Wiki Home
News
Recent Changes

AppFuse

Homepage
  - Korean
  - Chinese
  - Italian
  - Japanese

QuickStart Guide
  - Chinese
  - French
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish
  - Japanese

User Guide
  - Korean
  - Chinese

Tutorials
  - Chinese
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish

FAQ
  - Korean

Latest Downloads

Other Applications

Struts Resume
Security Example
Struts Menu

Set your name in
UserPreferences


Referenced by
Articles
Articles_cn
Articles_de
Articles_pt
Articles_zh
HibernateRelationshi...




JSPWiki v2.2.33

[RSS]


Hide Menu

HibernateRelationships


Difference between version 107 and version 99:

At line 2 changed 1 line.
This is a tutorial to show how to create and manage Hibernate relationships within [AppFuse]. This tutorial was written using AppFuse 1.8. All of the code for this tutorial is downloadable. To begin, I created a new application with an app/db name of blog/blog.
This is a tutorial to show how to create and manage Hibernate relationships within [AppFuse]. This tutorial was written using AppFuse 1.8.2. All of the code for this tutorial is downloadable at [http://static.appfuse.org/downloads/appfuse-hr.zip].
At line 9 changed 1 line.
* [1] Create Weblog.java, Entry.java and add XDoclet tags
* [1] Create Weblog.java, Entry.java and Category.java domain objects
At line 34 changed 1 line.
The first thing you need to do in this tutorial is these two object to persist. Create both a ''Weblog.java'' class and an ''Entry.java'' class (in the src/dao/**/model directory). The necessary XDoclet tags for these entities is included on the ''getter'' method's javadoc. You can download these files using the links below. Note that javadocs have been eliminated for brevity.
The first thing you need to do in this tutorial is these two object to persist. Create a __Weblog.java__ class and an __Entry.java__ class (in the src/dao/**/model directory). The necessary XDoclet tags for these entities is included on the ''getter'' method's javadoc. You can download these files using the links below. Note that javadocs have been eliminated for brevity.
At line 41 changed 1 line.
!![[Many-to-One] Create a new Category object and modify Entry.java to use it [#2]
Create a __Category.java__ object to act as an entity for persisting category information about weblog entries. Each category can have many entries. This class contains the following properties:
At line 43 removed 2 lines.
A category object will act as an entity for persisting category information about weblog entries. Each category can have many entries. This class contains the following properties:
At line 53 changed 1 line.
Add the 3 new mapping files to the "sessionFactory" bean's ''mappingResources'' property in __src/org/appfuse/dao/hibernate/applicationContext-hibernate.xml__.
Add the 3 new mapping files (that will be generated) to the "sessionFactory" bean's ''mappingResources'' property in __src/org/appfuse/dao/hibernate/applicationContext-hibernate.xml__.
At line 68 changed 1 line.
!![2] [[Many-to-Many] A Weblogs can have many Users, a User can have many Weblogs [#2]
!![[Many-to-Many] A Weblogs can have many Users, a User can have many Weblogs [#2]
At line 96 changed 1 line.
%%note __NOTE:__ The reason a java.util.List is used instead of a java.util.Set is because this is because [Sets aren't supported for indexed properties in Struts|http://www.mail-archive.com/[email protected]/msg26289.html].
%%note __NOTE:__ The reason a java.util.List is used instead of a java.util.Set is because this is because [Sets aren't supported for indexed properties in Struts|http://www.mail-archive.com/[email protected]/msg26289.html].%%
At line 122 changed 1 line.
Create a unit test so you can verify that everything actually works. Create a __WeblogDaoTest__ class in your test/dao/**/model directory. This file should extend GenericDaoTest. If you're using anything less than AppFuse 1.9, you may have to modify GenericDAOTest's "dao" variable so its __protected__ instead of private. Copy the code below into this test:
Create a unit test so you can verify that everything actually works. Create a __WeblogDaoTest__ class in your test/dao/**/dao directory. This file should extend GenericDaoTest. If you're using anything less than AppFuse 1.9, you may have to modify GenericDAOTest's "dao" variable so its __protected__ instead of private. Copy the code below into this test:
At line 168 changed 1 line.
Make sure you run __ant setup-db__ before running _ant test-dao -Dtestcase=UserDAO__. When running the test, you'll probably get a ''LazyInitializationException''. To solve this, change BaseDaoTestCase to extend Spring's [AbstractTransactionalDataSourceSpringContextTests|http://www.springframework.org/docs/api/org/springframework/test/AbstractTransactionalDataSourceSpringContextTests.html] if it doesn't already. In additional, you'll need to make a few changes to the existing tests so all the tests pass. [Here is a patch|LazyDaoTests.diff]. At a minimum, you'll need to fix BaseDAOTestCase and GenericDAOTest (onSetUp() -> onSetupBeforeTransaction()).
Make sure you run __ant setup-db__ before running __ant test-dao -Dtestcase=UserDAO__. When running the test, you'll probably get a ''LazyInitializationException''. To solve this, change BaseDaoTestCase to extend Spring's [AbstractTransactionalDataSourceSpringContextTests|http://www.springframework.org/docs/api/org/springframework/test/AbstractTransactionalDataSourceSpringContextTests.html] if it doesn't already. In additional, you'll need to make a few changes to the existing tests so all the tests pass. [Here is a patch|LazyDaoTests.diff]. At a minimum, you'll need to fix BaseDAOTestCase and GenericDAOTest (onSetUp() -> onSetupBeforeTransaction()).
At line 190 changed 1 line.
* @hibernate.bag name="entries" lazy="false" inverse="true" cascade="delete"
* @hibernate.bag name="entries" lazy="false" cascade="all"

Back to HibernateRelationships, or to the Page History.