Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Teneo/Hibernate/QuickStart"

Line 25: Line 25:
 
* create objects and persist them
 
* create objects and persist them
 
* read the objects back
 
* read the objects back
 +
 +
 +
== Try it ==
 +
 +
You can try out mysql or another database by changing the properties in the beginning of the quick start:
 +
<source lang="java">
 +
props.setProperty(Environment.DRIVER, "com.mysql.jdbc.Driver");
 +
props.setProperty(Environment.USER, "root");
 +
props.setProperty(Environment.URL, "jdbc:mysql://127.0.0.1:3306/" + dbName);
 +
props.setProperty(Environment.PASS, "root");
 +
props.setProperty(Environment.DIALECT, org.hibernate.dialect.MySQLInnoDBDialect.class.getName());
 +
</source>
 +
Make sure that the jdbc driver is in the classpath and that the database (called library) is created before running the quick start.
 +
 +
As a next step you can change the ecore model and regenerate the model code and re-run the quick start. You will see the changes reflected in the database schema.

Revision as of 02:26, 3 March 2010

This quick start shows how EMF, Teneo and Hibernate work together to automatically creates the database schema and persist EMF objects.

The quick start tutorial uses the example project which you can download here.

This tutorial assumes some basic knowledge of EMF. If you are new to EMF then it can make sense to first try one of the core EMF tutorials which you can find here.

Initial Setup

The quick start assumes that you have a running Eclipse with EMF and Teneo installed. In addition the Teneo dependencies (incl. hsqldb and mysql drivers) should be installed. See the Download & Install page for more information.

The quick start uses hsqldb but it can easily be changed to use mysql or another database. For other databases than hsqldb and mysql you need to take make sure that the jdbc driver is in the classpath of the org.eclipse.emf.teneo.hibernate.examples project.

For mysql and other non-in-memory databases you have to create the database up-front (so not the tables inside the database but just the database itself). For the quick start the database name should be: library.

Running 'quick start'

After downloading the examples project from cvs you can directly run the quick start program. Open the project and navigate to the QuickStart.java file and right click and select 'Run As > Java Application'. You will see several things getting printed to the console (one of them is the generated Hibernate mapping).

This run takes the following steps:

  • reads the EPackage model from the generated EPackage file.
  • generate a hibernate mapping for the EPackage
  • create the database (on hsqldb)
  • create objects and persist them
  • read the objects back


Try it

You can try out mysql or another database by changing the properties in the beginning of the quick start:

		props.setProperty(Environment.DRIVER, "com.mysql.jdbc.Driver");
		props.setProperty(Environment.USER, "root");
		props.setProperty(Environment.URL, "jdbc:mysql://127.0.0.1:3306/" + dbName);
		props.setProperty(Environment.PASS, "root");
		props.setProperty(Environment.DIALECT, org.hibernate.dialect.MySQLInnoDBDialect.class.getName());

Make sure that the jdbc driver is in the classpath and that the database (called library) is created before running the quick start.

As a next step you can change the ecore model and regenerate the model code and re-run the quick start. You will see the changes reflected in the database schema.

Back to the top