CDO/Hibernate Store/Configuration and Setup
The configuration of the CDO server with the CDO Hibernate Store consists of 2 parts: 1) a cdo-server.xml configuration file, 2) a launch configuration in Eclipse. The description here assumes that the CDO server will be started from Eclipse.
This document discusses the setup and configuration of the CDO server. This page assumes that required plugins have been downloaded and installed and that they are correctly loaded/installed after restarting Eclipse.
This page uses the org.eclipse.emf.cdo.examples.hibernate.server project as an example. This development project can be downloaded from here:
- server: dev.eclipse.org
- main directory: /cvsroot/modeling
- path: org.eclipse.emf/org.eclipse.emf.cdo/examples/org.eclipse.emf.cdo.examples.hibernate.server
There are 2 relevant (for configuration) files in this example project:
- the config/cdo-server.xml (CDO as a default uses the cdo-server.xml in the config directory)
- the CDOHibernateServer.launch file
You can start the CDO Server directly by right-clicking the CDHibernateServer.launch and then select: Run As > CDOHibernateServer.launch. The configuration file is discussed in some more detail.
An example configuration file is shown below. It consists of different sections: acceptor definition: defines the communication protocol and port repository: contains CDO properties, Teneo properties and Hibernate properties store: within the repository tag a store is defined (type="hibernate") and a mapping provider is specified (teneo)
Here is the full listing:
<?xml version="1.0" encoding="UTF-8"?> <cdoServer> <!-- <acceptor type="http"/> --> <acceptor type="tcp" listenAddr="0.0.0.0" port="2036"> <!-- <negotiator type="challenge" description="/temp/users.db"/> --> </acceptor> <repository name="repo1"> <property name="overrideUUID" value=""/> <property name="supportingAudits" value="false"/> <property name="verifyingRevisions" value="false"/> <property name="currentLRUCapacity" value="10000"/> <property name="revisedLRUCapacity" value="10000"/> <!-- NOTE: the following properties are currently defined on repository level. In future builds of the CDO Hibernate store these properties are defined within the store and mappingProvider tags. --> <!-- Teneo options: see: http://www.elver.org/hibernate/options.html or the org.eclipse.emf.teneo.PersistenceOptions class --> <!-- The following value must be set normally like this, use this in your app also --> <property name="teneo.mapping.cascade_policy_on_non_containment" value="PERSIST,MERGE"/> <!-- some demo settings --> <!-- using an external xml file for annotations, note this xml file is located in the org.eclipse.emf.cdo.examples.hibernate.annotations which is available on the cdo server by adding it to the CDOHibernateServer.launch configuration --> <property name="teneo.mapping.persistence_xml" value="/META-INF/company_model_teneo_annotations.xml"/> <!-- create tables for each subclass with joining to the parent table --> <property name="teneo.mapping.inheritance" value="JOINED"/> <!-- create an index for each fk --> <property name="teneo.mapping.add_index_for_fk" value="true"/> <!-- Hibernate properties , see: http://docs.jboss.org/hibernate/stable/core/reference/en/html_single/#configuration-optional --> <property name="hibernate.hbm2ddl.auto" value="update"/> <property name="hibernate.show_sql" value="false"/> <property name="hibernate.connection.pool_size" value="10"/> <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/> <!-- Setting for hsqldb --> <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/> <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver"/> <property name="hibernate.connection.url" value="jdbc:hsqldb:mem:cdohibernate"/> <property name="hibernate.connection.username" value="sa"/> <property name="hibernate.connection.password" value=""/> <property name="hibernate.connection.autocommit" value="true"/> <!-- Setting for mysql <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect"/> <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/> <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/cdohibernate"/> <property name="hibernate.connection.username" value="root"/> <property name="hibernate.connection.password" value="root"/> --> <store type="hibernate"> <mappingProvider type="teneo"> </mappingProvider> </store> </repository> </cdoServer>
This file is present in the config folder of the org.eclipse.emf.cdo.examples.hibernate.server project.
Note: as is noted in the config file, the location of the Teneo and Hibernate properties will change in future builds (with backward compatibility support). In the future the Teneo properties are placed within the mappingProvider tag and the Hibernate properties directly within the store tag.
Each of the different property sections is discussed in more detail.
Teneo supports many (40+) global properties to control the mapping logic itself, database artifact naming and entity naming. All the options are described in the Teneo options page.
The options are also described in the PersistenceOptions class. By installing the SDK, see the download and install section you will have the source code. Check this class for textual representation of the options (which prefix to use).
One option: teneo.mapping.cascade_policy_on_non_containment, needs to be set to: PERSIST,MERGE. This is already done in the cdo-server.xml (and the example above).
There are many hibernate options. The most important ones (to connect to the database) are shown above, there are however many more. Check out the documentation here.
Additional Hibernate or other Config files
There are cases where it is required to add additional Hibernate or EHCache or other configuration files to the CDO server. These files should be made visible to the hibernate plugin. To accomplish this the following has to be done:
- place the files in a separate plugin
- let this plugin depend on the org.eclipse.emf.cdo.server.hibernate plugin and possibly also on the hibernate plugin (select the correct plugin with version 3.3.2 or higher)
- make sure that the configuration files are copied to the output folder, they should be listed in the build.properties in the bin.include/binary
- export (in the MANIFEST.MF) the location containing the configuration file.
The config file shown above (and in the examples project) defines that hsqldb should be used. This can easily be changed to another database. Make sure that the driver for the other database is available as a plugin.
Also note that Hibernate will not create a database, so if the store is used with another database server then the database needs to be created manually. The tables don't need to be created, this part is done by Hibernate.
Run Launch Config
The examples project contains an example CDOHibernateServer.launch configuration. To run it right click on it and then select: Run As > CDOHibernateServer.
The CDO launch config has a few special settings:
- on the first page of the launch config the 'Program to run' should be set to: an application with selected the org.eclipse.emf.cdo.server.app.
- on the second page the path to the config file is defined, make sure that it is set like this (see the selected text in the arguments):
The config file path points to the org.eclipse.emf.cdo.examples.hibernate.server/config, the cdo-server.xml is automatically found by CDO.
- on the third page, for convenience the plugins are not selected individually but all plugins are selected.
If you want a more specific selection then you need to manually select the correct plugins. For the CDO runtime at least the following plugins need to be selected in the launch config:
In addition there are common platgorm plugins which need to be selected.
There is more CDO documentation on creating CDO launch configs: