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_pt
CreateDAO_es
CreateDAO_pt
CreateDAO_sp
CreateDAOiBATIS
CreateManager
CreateManager_es
CreateManager_ko
CreateManager_zh
...and 3 more




JSPWiki v2.2.33

[RSS]


Hide Menu

CreateDAO


Difference between version 30 and version 29:

At line 24 changed 1 line.
* [5] Notify Hibernate that this object exists in ServiceLocator (for tests) and in hibernate.cfg.xml (for webapp)
* [5] Notify Spring/Hibernate that this object exists in src/dao/**/hibernate/applicationContext-hibernate.xml
At line 29 changed 1 line.
The first thing we need to do is create an object to persist. Let's create a simple "Person" object (in the src/ejb/**/persistence directory) that has an id, a firstName and a lastName (as properties).
The first thing we need to do is create an object to persist. Let's create a simple "Person" object (in the src/dao/**/model directory) that has an id, a firstName and a lastName (as properties).
At line 33 changed 1 line.
package org.appfuse.persistence;
package org.appfuse.model;
At line 50 changed 1 line.
In the code snippet above, we're extending [BaseObject|http://raibledesigns.com/downloads/appfuse/api/org/appfuse/persistence/BaseObject.java.html] because it has the following useful methods: toString(), equals(), hashCode() - the latter two
In the code snippet above, we're extending [BaseObject|http://raibledesigns.com/downloads/appfuse/api/org/appfuse/model/BaseObject.java.html] because it has the following useful methods: toString(), equals(), hashCode() - the latter two
At line 80 removed 2 lines.
;:%%(color: blue)''I try to remember to add the Person object to ServiceLocator.java and hibernate.cfg.xml at this point. This is covered in [step 5|5].''%%
At line 91 changed 1 line.
If you want to look at the Person.hbm.xml file that Hibernate generates for you, look in the build/ejb/gen/**/persistence directory. Here's the contents of Person.hbm.xml (so far):
If you want to look at the Person.hbm.xml file that Hibernate generates for you, look in the build/dao/gen/**/hibernate directory. Here's the contents of Person.hbm.xml (so far):
At line 103 changed 1 line.
name="org.appfuse.persistence.Person"
name="org.appfuse.model.Person"
At line 163 added 1 line.
At line 167 changed 1 line.
To start, create a PersonDaoTest.java class in the test/ejb/**/persistence directory. This class should extend [BaseDaoTestCase|http://raibledesigns.com/downloads/appfuse/api/org/appfuse/persistence/BaseDaoTestCase.java.html], which already exists in this package. This parent class is mainly used for automatically loading a .properties file (ResourceBundle) that has the same name as your *Test.class. In this example, if you put a PersonDaoTest.properties file in the same directory as PersonDaoTest.java, this file's properties will be available via an "rd" variable.
To start, create a PersonDaoTest.java class in the test/dao/**/persistence directory. This class should extend [BaseDaoTestCase|http://raibledesigns.com/downloads/appfuse/api/org/appfuse/persistence/BaseDaoTestCase.java.html], which already exists in this package. This parent class is used to load [Spring's|http://www.springframework.org] ApplicationContext (since Spring binds the layers together), and for automatically loading a .properties file (ResourceBundle) that has the same name as your *Test.class. In this example, if you put a PersonDaoTest.properties file in the same directory as PersonDaoTest.java, this file's properties will be available via an "rb" variable.
At line 185 removed 5 lines.
//~ Constructors ===========================================================
public PersonDaoTest(String name) {
super(name);
}
At line 192 changed 2 lines.
super.setUp();
dao = (PersonDao) DAOFactory.getInstance(conn, PersonDao.class);
log = LogFactory.getLog(PersonDaoTest.class);
dao = (PersonDao) ctx.getBean("personDao");
At line 198 removed 1 line.
super.tearDown();
At line 201 removed 1 line.
At line 208 changed 1 line.
The code you see above is what we need for a basic JUnit test that initializes and destroys our PersonDao. The "conn" object is initialized (and obtains a connection) in the [BaseDaoTestCase|http://raibledesigns.com/downloads/appfuse/api/org/appfuse/persistence/BaseDaoTestCase.java.html] class.
The code you see above is what we need for a basic JUnit test that initializes and destroys our PersonDao. The "ctx" object is a reference to Spring's ApplicationContext, which is initialized in the [BaseDaoTestCase|http://raibledesigns.com/downloads/appfuse/api/org/appfuse/persistence/BaseDaoTestCase.java.html] class.
At line 202 added 5 lines.
[{Java2HtmlPlugin
ctx = new ClassPathXmlApplicationContext("/applicationContext.xml");
}]
At line 292 changed 1 line.
First off, create a PersonDao.java interface in the src/ejb/**/persistence directory and specify the basic CRUD methods for any implementation classes. ''I've eliminated the JavaDocs in the class below for display purposes.''
First off, create a PersonDao.java interface in the src/dao/**/persistence directory and specify the basic CRUD methods for any implementation classes. ''I've eliminated the JavaDocs in the class below for display purposes.''
At line 308 changed 1 line.
At this point, you should be able to compile all the source in src/ejb and test/ejb using "ant compile-ejb". However, if you try to run "ant test-ejb -Dtestcase=PersonDao", you will get an error: <span style="color: red">DAOException: no DAOHibernate class</span>.
At this point, you should be able to compile all the source in src/dao and test/dao using "ant compile-dao". However, if you try to run "ant test-dao -Dtestcase=PersonDao", you will get an error: <span style="color: red">DAOException: no DAOHibernate class</span>.

Back to CreateDAO, or to the Page History.