Hibernate
Hibernate is an object-relational mapping solution for the Java language.
Medea provides a set of templates to generate value object classes and Hibernate configuration files from a class diagram.
Model
Consider this class diagram. Note that all classes are marked with entity stereotype.
The diagram is complex enough to show Hibernate features:
- Packages
- Classes
- Associations
- named
- directed
- bidirectional
- Generalizations
You may want to set up a new project to test this target. Use mycompany model; edit build.properties file and execute copy_res target as described in Quick Start section.
Templates
Two main templates in this target are:
- Hibernate: creates Hibernate configuration files for all classes marked with entity stereotype
- Data: creates Java POJO classes for all classes marked with entity stereotype
These templates produce all artifacts needed to create a Hibernate persistence tier. You can incorporate the results to your project. Medea provides other templates and build targets to create a Hibernate archive and service file to deploy to JBoss application server; PersistenceFacade and EJB module to use in a 3-tier J2EE application. Look for more details in CRUD with Jsp section.
- hibernate-service: creates JBoss service configuration file
- HibernateFacadeBean: Hibernate implementation of Facade interface to be used in Facade stateless session EJB
- HibernateLocator: helper class to look up Hibernate session
- FacadeLocator: helper class to look up Facade EJB
- Facade: interface on the Facade EJB
- Locator: helper class for jndi lookup
- PersistenceManager: interface with persistence methods for all entities to be used in front end
- HibernateManager: Hibernate implementation of PersistenceManager interface
- PersistenceManagerFactoryHibernate: helper PersistenceManagerFactory creates Hibernate implementation of PersistenceManager
- ejb-jar_har: ejb-jar.xml with Facade EJB
- jboss_har: jboss.xml listing Hibernate module
- jboss-app_har: jboss-app.xml listing Hibernate module
Build targets
Medea provides the following build targets to create Hibernate components:
- trans_hibernate: Transform config files and ejb facade for Hibernate
- trans_facade_har: Transform source files for Hibernate persistence facade
- trans_jboss_har: Transform config files for JBoss
- compile_har: Compile value object classes for Hibernate
- jar_har: Make a Hibernate archive file with value object classes and config files
- redeploy_har: Deploy Hibernate archive by copying har file