Problems Generating ORM Code

Hello,

I have not been able to generate working ORM code, so I created small test case.

My environment is as follows:

VP-UML Professional Version 6.0 (Build sp2_20070526)

OS: Mac OS X Version 10.4.9 - 2 GB Ram

Attachments:
IDemo.vpp
VP-UML.log

Below is a detailed list of steps I have taken and the results produced.

 
1. Create Entity Relationship Diagram

     - Create ORM package in Eclipse e.g. com.arkadias.idemo.orm
     - Place odbc driver file in ~orm.lib
     - Create new ER diagram in VP-UML
     - Assign tables, columns and data types on ERD

2. Create Class diagram from ER diagram

   - Create Class diagram from ER diagram
     - Tools/Object-Relational Mapping (ORM)/Synchronize to Class Diagram
     - Assign <<ORM Persistable>> stereotype as needed

===============================================
== First attempt
===============================================
3. Create database and persistable objects (ORM) from ERD

   - Create database manually (if needed)
   - Generate Code and Database from ERD
     - Tools/Object-Relational Mapping (ORM)/Wizards
       - Welcome page
         - Language: Java
         - Wizards: Generate Code and Database from ERD
       - Class Details Configuration page
         - Package: ORM package name (e.g. idemo.orm)         
       - Database Configuration page
         - Driver file select from ~orm/lib
       - Generate Code page
         - Error Handling: Throw PesistentException
         - Exception Handling: Print to log4j
         - Default Lazy Collection Initialization: Lazy for small data set, Extra for large
         - Mapping Type: Annotation
         - Output Path: ~orm
         - Deploy to: (as appropriate for target system) e.g. Standalone Application
         - Association Handling: Smart (handles both side of 1 - many updates)
         - Persistent API: Factory Class
         - Generate Criteria: Check (generates criteria (query) objects
         - Serializable: Not Check
         - Cache Options: EHCache
         - Select Optional Jar: (default)
         - Advance Settings:
         - Samples: As desired (generates ORM usage sample code)
         - Scripts: None (Script execution not supported until VP-Suite 3.1 ~06.2007)
         
4. Correct ORM code errors

   Compile time errors
   - Rename (refactor) ~orm package to match package name in source e.g.
     - com.arkadias.idemo.orm.src.com.arkadias.idemo.orm > com.arkadias.idemo.orm
     - com.arkadias.idemo.orm.src.ormsamples > com.arkadias.idemo.orm.samples
   - Add ~orm.lib jars to project java build path

   Runtime errors
   - HibernateException: /ormmapping/IDemo.cfg.xml not found
     - Rename com.arkadias.idemo.orm.src.ormmapping -> ormmapping
   - Hibernate cache errors
     - WARN EhCacheProvider:86 - Could not find configuration [hibernate.test.org.hibernate.cache.UpdateTimestampsCache]; using defaults.
     - WARN EhCacheProvider:86 - Could not find configuration [hibernate.test.org.hibernate.cache.StandardQueryCache]; using defaults.

===============================================
=== Second attempt
===============================================
3. Create database and persistable objects (ORM) from Class Diagram

   - Create database manually (if needed)
   - Generate Code and Database from Class Diagram
     - Tools/Object-Relational Mapping (ORM)/Wizards
       - Welcome page
         - Language: Java
         - Wizards: Generate Code and Database from Class Diagram
       - Selecting Classes page
         - Confirm default settings
       - Table Details Configuration
         - Confirm default settings
       - Database Configuration page
         - Export to Database: Check if desired
         - Generate DDL: Check if desired
         - Quote SQL Identifier: Auto
         - Table Character set: UTF8
         - Connection: JDBC
         - JDBC
           - Use connection pooling: Check
           - Driver MySQL (Connector/J Driver)
           - Driver file select from ~orm/lib
           - Connection URL & User: as appropriate
           - Engine: Default
           - Set as default: Check
           - Test Connection: Confirm connection
       - Generate Code page
         - Generate Code: Check
         - Error Handling: Throw PesistentException
         - Exception Handling: Print to log4j
         - Default Lazy Collection Initialization: Lazy for small data set, Extra for large
         - Mapping Type: Annotation
         - Output Path: ~orm
         - Deploy to: Standalone Application (as appropriate for target system)
         - Association Handling: Smart (handles both side of 1 - many updates)
         - Persistent API: Factory Class
         - Generate Criteria: Check (generates criteria (query) objects
         - Serializable: Not Check
         - Cache Options: EHCache
           - Default Settings ok
           - Classes Cache Configuration
             - Enable cache for appropriate classes (Set Read-Only)
         - Select Optional Jar: (default)
         - Advance Settings: Default values Ok
         - Samples: As desired (generates ORM usage sample code)
         - Scripts: None (Script execution not supported until VP-Suite 3.1 ~06.2007)
         - Generate Filter and Web Application Descriptor: Not Checked
         
4. Correct ORM code errors

=== Failed /tmp/orm43978/src/com/arkadias/idemo/orm/IDemoName.java (No such file or directory)

ORM Message:
[14:16:59] [Message] Generating code...
[14:16:59] [Message] Copying libraries...
[14:17:03] [Message] Generating configuration file...
[14:50:32] [Message] Generating code...
[14:50:32] [Message] Copying libraries...
[14:50:37] [Message] Generating configuration file...
[14:50:37] [Error] java.io.FileNotFoundException: /tmp/orm43978/src/com/arkadias/idemo/orm/IDemoName.java (No such file or directory)
[14:54:22] [Message] Generate code finish...

=== BUT: The path mentioned in the [Error] above does exist, in fact, the entire structure exists...

The annotations.jar and orm.jar are missing from the Eclipse workspace.
These files were generated and exist in /tmp/orm43978

Copy /tmp/orm43978/lib/* -> {project}/src/com/arkadias/idemo/orm/lib/
seems to get us to the state after Code Generation in ==First Attempt above

   Compile time errors
   - Rename (refactor) ~orm package to match package name in source e.g.
     - com.arkadias.idemo.orm.src.com.arkadias.idemo.orm > com.arkadias.idemo.orm
     - com.arkadias.idemo.orm.src.ormsamples > com.arkadias.idemo.orm.samples
   - Add ~orm.lib jars to project java build path

   Runtime errors
   - HibernateException: /ormmapping/IDemo.cfg.xml not found
     - Rename com.arkadias.idemo.orm.src.ormmapping > ormmapping
     - No ormmapping files were generated

I’m stuck at this point, any insight, suggestions, etc would be greatly appreciated.

Best regards,

-Glen Ihrig
VP-UML.log
IDemo.vpp

Hello gihrig,

Thank you for your post. I just tried to walk through your steps to see what the problem is. However, when I am at step 4, I do not see the error you stated. Instead, I found error for package declaration because the output I set, ~orm, was not the project path of the Eclipse Java project but a folder under the Java project. As a consequent, the source folder cannot be identified. Could you try to set the output path to be the Java project path? This may solve the problem.

I am also attaching a screenshot to show you my project hierarchy after finishing step 3 to ensure I am on the right track.

Best regards,
Jick

structure.png

Hello Jick,

Thank you for taking the time to look at my problem.

I’m afraid I did not make clear that I was using a shortcut notation. When I wrote ~orm I was using the “~” symbol to represent the path to that point, similar to the user’s home directory notation used in Unix/Linux. I am sorry for the misinformation.

In any case, your suggestion was very helpful, it got me onto the right track in resolving my problem.

I am now able to generate working ORM code that requires no modification. I still have a question about some of the generated files, please see that at the end of this post.

For reference, below is a revised list of steps that produces working ORM code.


===============================================
== Third attempt - From ERD - Output dir redefined, Cache disabled, etc.
Notes: 
{workspace_dir} is Eclipse workspace, home to all Eclipse projects.
  e.g. /Users/glen/Documents/Eclipse/
{project_dir} is the home directory for current project.
  e.g. {workspace_dir}/com.arkadias.idemo/

*** indicates changes from First attempt, above.
===============================================
1. Create a new Eclipse project ***

  - Create new project in Eclipse: File/New/Project/Java Project
    - Project name: com.arkadias.idemo
    - Contents: Create new project in workspace
    - JRE: use default JRE...
    - Project layout: Create separate source and output folders
      - {project_dir} is created as: {workspace_dir}/com.arkadias.idemo

2. Install JDBC driver jar ***

  - Create {project_dir}/lib
  - Copy JDBC driver jar here
  - Add JDBC driver jar to Build Path

3. Create Entity Relationship Diagram

     - Create new ER diagram in VP-UML
     - Assign tables, columns and data types on ERD

4. Create Class diagram from ER diagram

   - Create Class diagram from ER diagram
     - Tools/Object-Relational Mapping (ORM)/Synchronize to Class Diagram
     - Assign <<ORM Persistable>> stereotype as needed
     - Assign package to ORM Class Diagram e.g. com.arkadias.idemo.orm

5. Create database and persistable objects (ORM) from ERD

   - Create database manually (if needed) e.g. database name idemo
   - Generate Code and Database from ERD
     - Tools/Object-Relational Mapping (ORM)/Wizards
       - Welcome page
         - Language: Java
         - Wizards: Generate Code and Database from ERD
       - Class Details Configuration page
***      - Package: Leave Blank - VP-UML picks up "com.arkadias.idemo.orm" from Class Diagram
       - Database Configuration page
***      - Driver file: {project_dir}/com.arkadias.idemo/lib/com.mysql-connector-java-5.0.4-bin.jar
         - Provide Connection URL and User data as appropriate
         - Confirm Test Connection passes
       - Generate Code page
         - Error Handling: Throw PesistentException
         - Exception Handling: Print to log4j
         - Default Lazy Collection Initialization: Lazy for small data set, Extra for large
         - Mapping Type: Annotation
***      - Output Path: {project_dir} e.g. /Users/glen/Documents/Eclipse/com.arkadias.idemo/
         - Deploy to: (as appropriate for target system) e.g. Standalone Application
         - Association Handling: Smart (handles both side of 1 - many updates)
         - Persistent API: Factory Class
         - Generate Criteria: Check (generates criteria (query) objects)
         - Serializable: Check
***      - Cache Options: Disable
         - Select Optional Jar: (default)
         - Advance Settings: (default)
         - Samples: Samples only (generates ORM usage sample code)
         - Scripts: None
       - Finish to generate Code
       - Add {project_dir}/lib/annotations.jar and orm.jar to Build Path
         
7. Test generated ORM classes

   Sample code execution
   - CreateIDemoData.java            - pass
   - DeleteIDemoData.java            - pass
   - ListIDemoData.java              - pass
   - RetrieveAndUpdateIDemoData.java - pass

At this point, my Eclipse project looks like this:
http://arkadia-systems.com/images/Eclipse_IDemo_ORM.jpg

My Eclipse/Java project folder looks like this
http://arkadia-systems.com/images/Eclipse_ProjectDir_IDemo.jpg

As noted above, everything works as expected.

There is still a problem with caching, but for clarity, I will open a new thread for that.

I am also wondering if I need to include the ormmapping folder when I package my application for distribution.

Because I chose “Mapping Type: Annotation”, I did not expect this folder to be generated. When I renamed this folder, the sample program files still worked as expected.

Are these files only required for VP-UML to interact with the Java project, or do they serve another purpose?

Your comments on this are much appreciated.

Best regards,

-Glen