Simple Pojo Example
This project demonstrates how to generate and interact with Entity beans generated by the SimplePojoGenerator class. The generated Entities are are standard Entity beans which inherit Serializable.
Once generated, these pojos behave exactly like a normal JPA entity. Test code for this project can be seen in the src/com/dal4j/sample/simple/app/TestApp.java file.
Pojo Generation
This project comes with pre-generated Entity beans which can be found in the src/com/dal4j/sample/simple/ejb/entity directory. To re-generate these classes (to undersand how code generation works) do the following.
NOTE: To perform code generation a MySQL or SQLServer database server is required.
1. Create the sample database, see README.txt in the samples/db directory.
2. Edit the appropriate configuration file found in samples/simple/bin:
config-sqlserver.xml - If the sample DB is in a sqlserver database.
config-mysql.xml - If the sample DB is in a mysql database.
In the configuration file, url, user, pwd, and instance as needed:
3. From samples/sample in a dos or unix shell run from the bin directory:
DOS: classgen <appropriate-config-file.xml>
Unix/Cygwin: classgen.sh appropriate-config-file.xml
For a SQL server database.
classgen.sh config-sqlserver.xml
For a MySQL server database.
classgen config-mysql.xml
4. If the command worked, the code was generated to src/com/dal4j/sample/simple/ejb/entity
5. Edit META-INF/persistence.xml with your database connection information.
In persistence.xml,change the following as required to connect to you database:
<property name="eclipselink.jdbc.driver" value="net.sourceforge.jtds.jdbc.Driver"/>
<property name="eclipselink.jdbc.url" value="jdbc:jtds:sqlserver://localhost:1433;databaseName=dal4j"/>
<property name="eclipselink.jdbc.password" value="dal4j"/>
<property name="eclipselink.jdbc.user" value="dal4j"/>
6. Re-compile the code, from the samples/simple directory, run: ant
NOTE: Ant must be in your path for this to work.
7. At this points, tests can be executed... See 'Test Execution'
Test Execution
To run the test applicationl, run the following command from the
samples/simple/bin directory:
DOS: run
Unix/Cygwin: run.sh