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/FAQ"

(Troubleshooting the OR Mapper Menu Option)
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__TOC__
 
__TOC__
 +
 +
===Lazy loading (Hibernate Proxying) of many-to-one does not work===
 +
To get lazy loading of many-to-one associations working you have to set the option: [[Teneo/Hibernate/Configuration_Options|SET_PROXY]] to "true".
 +
 +
Also you need to have 'resolve proxies' to false in your model for the association, otherwise EMF will force a load by calling several methods on the proxied object.
 +
 +
===Mapping Exception Unknown Entity===
 +
This exception is thrown when building the EntityManagerFactory. The entityPersistors in the Hibernate session are all keyed by the mapping's entity-name. In Teneo/EMF's case, the eClass name is the key, but Hibernate tries to use the impl class name as the key.
 +
 +
See [http://www.eclipse.org/forums/index.php?t=tree&th=168644&#page_top this post] on the forum.
 +
 +
See [https://bugs.eclipse.org/bugs/show_bug.cgi?id=241537 this bugzilla] for a workaround. Or try setting the following hibernate property:
 +
hibernate.ejb.metamodel.generation=disabled
  
 
===Derby and Hibernate IDBag===
 
===Derby and Hibernate IDBag===
Apparently the Hibernate Derby driver does not handle Hibernate idbags correctly. See this link here for more information.
+
Apparently the Hibernate Derby driver does not handle Hibernate idbags correctly. See this link [http://dev.eclipse.org/newslists/news.eclipse.tools.emf/msg37757.html here] for more information.
  
 
===DB Schema constraint error using MS Sql===
 
===DB Schema constraint error using MS Sql===
Line 40: Line 53:
  
 
===Troubleshooting the Mapping and Runtime layer/Hibernate===
 
===Troubleshooting the Mapping and Runtime layer/Hibernate===
The runtime layer uses commons-logging for logging. Here you can find an example log4j.properties file. This file should be placed directly in the src directory of your EMF Model project. Note: also check if Eclipse copies the file to your bin/build directory. For a plugin project this can be specified in the build.properties.
+
The runtime layer uses commons-logging for logging. Here you can find an example [[media:Teneo.log4j.properties.zip|log4j.properties]] file. This file should be placed directly in the src directory of your EMF Model project. Note: also check if Eclipse copies the file to your bin/build directory. For a plugin project this can be specified in the build.properties.
  
 
The example log4j.properties also contains log4j settings for Hibernate.
 
The example log4j.properties also contains log4j settings for Hibernate.
Line 53: Line 66:
  
 
When the console shows this exception: Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/emf/teneo/hibernate/mapper/GenerateHBM then you have not added the org.eclipse.emf.teneo.hibernate plugin to the dependencies of the model plugin.
 
When the console shows this exception: Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/emf/teneo/hibernate/mapper/GenerateHBM then you have not added the org.eclipse.emf.teneo.hibernate plugin to the dependencies of the model plugin.
 +
 +
See also this forum post: https://www.eclipse.org/forums/index.php/t/315151/
  
 
To analyze what the problem is first view the error log. The error log can be opened through: Window > Show View > Error Log. By doubleclicking on the lines in the error log you can get more information.
 
To analyze what the problem is first view the error log. The error log can be opened through: Window > Show View > Error Log. By doubleclicking on the lines in the error log you can get more information.
Line 64: Line 79:
  
 
===Cut and Paste does not work in the Editor===
 
===Cut and Paste does not work in the Editor===
Please look [[Teneo/Hibernate/Details#cutpaste|here]].
+
Please look [[Teneo/Hibernate/EMF_Hibernate_Integration_Details#Move_an_EObject_between_EContainers_or_support_cut_and_paste_in_the_EMF_editor|here]].
  
 
===Client-server scenario: when saving on the server always new objects are created or I get a duplicate key exception===
 
===Client-server scenario: when saving on the server always new objects are created or I get a duplicate key exception===
Line 155: Line 170:
 
         @Override
 
         @Override
 
         protected boolean isReadOnlyURI(URI uri) {
 
         protected boolean isReadOnlyURI(URI uri) {
                 boolean defaultReadOnly = super.isReadOnlyURI(uri);
+
                 return super.isReadOnlyURI(uri)
                if (defaultReadOnly == true
+
                                 && !uri.fileExtension().equals("ehb");
                                 && uri.fileExtension().compareTo("ehb") == 0) {
+
                        return false;
+
                } else {
+
                        return defaultReadOnly;
+
                }
+
 
         }
 
         }
 
}
 
}

Revision as of 07:43, 15 September 2014

Contents

Lazy loading (Hibernate Proxying) of many-to-one does not work

To get lazy loading of many-to-one associations working you have to set the option: SET_PROXY to "true".

Also you need to have 'resolve proxies' to false in your model for the association, otherwise EMF will force a load by calling several methods on the proxied object.

Mapping Exception Unknown Entity

This exception is thrown when building the EntityManagerFactory. The entityPersistors in the Hibernate session are all keyed by the mapping's entity-name. In Teneo/EMF's case, the eClass name is the key, but Hibernate tries to use the impl class name as the key.

See this post on the forum.

See this bugzilla for a workaround. Or try setting the following hibernate property: hibernate.ejb.metamodel.generation=disabled

Derby and Hibernate IDBag

Apparently the Hibernate Derby driver does not handle Hibernate idbags correctly. See this link here for more information.

DB Schema constraint error using MS Sql

Teneo generates the names of foreign key constraints. MS Sql reports errors if the FK constraint name are the same as table names. See this post on the EMF newsgroup. The solution is to set the option: PersistenceOptions.SET_FOREIGN_KEY_NAME to "false".

Duplicate method exception with javaassist

This exception occurs when using the same EStructuralFeature name in different EClasses related through the same super EClass. There can also be other cases where this occurs.

This seems to be a javaassist issue.

At this point the solution is to use cglib instead of javassist. See this 292151 bugzilla for more information.

File Not Found Exception for a file called: document-v13.dtd

This exception occurs when initializing a datastore.

It can happen when you have a xml file for annotations which contains illegal entities or entities which can not be resolved. For example . Check your annotations.xml and try again.

Another reason why it can happen is that you have a DOCTYPE tag in the top of the xml:

<!DOCTYPE persistence-mapping PUBLIC "-//APACHE//DTD Documentation V1.3//EN" "document-v13.dtd">

Issue: too many tables in join sql statement

When there are many associations in a model then it is possible that you encounter a 'too many tables' exception when executing a query in hibernate. A possible workaround is to control the default fetch behavior of hibernate. For example the hibernate.max_fetch_depth option can be set to a lower value (its default is 3). See also the section: 19.1. Fetching strategies, in the hibernate manual.

Unknown Entity

This exception can occur when you try to use the getReference or get methods on the EntityManager/Session objects and you call these methods using the Interface class name or the Implementation clas name. To solve this Teneo has a special entity naming strategy: EntityInterfaceNameStrategy. This entity naming strategy will use the interface name as the entity-name. You can set this naming strategy through this call: yourDataStore.getExtensionManager().registerExtension(EntityNameStrategy.class.getName(), EntityInterfaceNameStrategy.class.getName()). This call should be done after the datastore was created but before it is initialized.

org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1

This exception can occur when using synthetic id's in combination with the creation of multiple session factories. For example when doing test runs with a database clean up between the test run. The exception occurs because the Idenfifier Cache, which is used by Teneo to handle synthetic id's, is not in-sync with the database.

To solve this you have to clear the Identifier cache by calling: IdentifierCacheHandler.clear();

Troubleshooting the Mapping and Runtime layer/Hibernate

The runtime layer uses commons-logging for logging. Here you can find an example log4j.properties file. This file should be placed directly in the src directory of your EMF Model project. Note: also check if Eclipse copies the file to your bin/build directory. For a plugin project this can be specified in the build.properties.

The example log4j.properties also contains log4j settings for Hibernate.

If you use the runtime layer within a plugin then log messages will not appear in the console. In this case check the error log view (Window > Show View > Error Log) or let the log messages be written to a file.

Troubleshooting the automatic in-memory mapping

The mapping is generated in memory. To view the mapping created by Teneo please call the method getMappingXML on the HbDataStore. The returned String contains the Hibernate mapping.

Troubleshooting the OR Mapper Menu Option

If an error popup is shown or no popup box appears after the OR Mapper plugin is finished then an application error has occured within the OR Mapper.

When the console shows this exception: Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/emf/teneo/hibernate/mapper/GenerateHBM then you have not added the org.eclipse.emf.teneo.hibernate plugin to the dependencies of the model plugin.

See also this forum post: https://www.eclipse.org/forums/index.php/t/315151/

To analyze what the problem is first view the error log. The error log can be opened through: Window > Show View > Error Log. By doubleclicking on the lines in the error log you can get more information.

More debug information from Eclipse

As an extra debug enabling you can add the following line in the EMF editor plugin:

org.eclipse.osgi.framework.debug.Debug.DEBUG_GENERAL = true;

This will result in much more debugging information in the console.

Cut and Paste does not work in the Editor

Please look here.

Client-server scenario: when saving on the server always new objects are created or I get a duplicate key exception

What can be the case is that you did not explicitly model an id and/or version attribute in each type. Both are required to be modeled explicitly, see here.

Column name e_version not supported by database

Teneo will automatically add a version column to the database for each object. The default version column name is e_version. However not all databases support an _ in the column name. To set the version column name you can set an option as explained here.

Column names too long

Teneo creates foreign key column names by concatenating the name of the (e)class and the property name. The result can be a column name which is too long for certain databases. You can control the maximum column name length by setting the relevant runtime option, see here.

org.hibernate.DuplicateMappingException: Duplicate class/entitymapping

This exception occurs when two EClasses (of different EPackages) have the same name. To solve this you need to direct Teneo to use qualified EClass names, see here. Note that when using qualified EClass names that also HQL needs to use the qualified EClass names. The EClass names are qualified by prepending the nsprefix of the EPackage with a dot (.) as a separator.

Created new model through new model wizard: diagnostic error

The generated EMF model wizard allows invalid documents. When going through the wizard you need to select a type to create as the first document in the resource. The EMF model wizard creates an empty (all members are null) instance of this type and adds it to the Hibernate resource. Before the Hibernate resource is saved it checks if the content of the resource is valid. When nullable-constraints are violated a StoreValidationException (with Diagnostics) is thrown.

To solve this you should make your model more relaxed (make elements nullable) or add a small amount of code, which sets the non-nullable fields, to the model wizard. An example of this last solution is illustrated in the Tutorial.

java.lang.NoClassDefFoundError when starting/initializing runtime layer

When your model is divided over different projects/plugins then the dependency on org.eclipse.emf.teneo.hibernate has to be set in the project with the 'widest' classpath (the project with a classpath containing the other plugins). For example if you have the following two emf projects:

  • Core
  • Specific (which uses/imports Core)

Then the dependency should preferably be in the META-INF of the 'Specific' project. This is required otherwise Hibernate will not see the 'Specific' project.

No class def found: org.hibernate.proxy.ProxyFactory

This exception can occur when your classes have been enhanced by JPOX and you try to persist them via hibernate. Another reason can be that the name you used to register the SessionFactory does not correspond to the expected extension (e.g. library).

Could not determine type for: org.eclipse.emf.common.util.AbstractEnumerator, for columns: [org.hibernate.mapping.Column(enu)]

This exception can occur when you have a enumerate object type in your model. An enumerate object type differs from a standard enumerate because it has a nillable="true" attribute on the element, for example:

<element name="enu" type="this:SimpleEnum" nillable="true"/>
 
<simpleType name="SimpleEnum">
	<restriction base="xsd:NCName">
		<enumeration value="Enum1"/>
		<enumeration value="Enum2"/>
	</restriction>
</simpleType>

As a workaround add an Enumerated annotation (see ejb3 annotations on this site) to the element.

The resource is empty in the generated editor

The standard behavior of a Hibernate resource is to only read types which have no container in the model. All other EObjects can be reached from these top-entities. However, this means that even if an EObject instance does not have a container but can be contained according to the model then it will still not be loaded in the resource. A common model is a an object which contains itself, for example a folder-like model. Workaround: to workaround this issue you should load the resource using specific queries, see customizing load behavior.

Update manager does not find the upgrade of the EMF Hibernate plugin

As a workaround use find new features to install a new version of the EMF Hibernate plugin.

Editor does not start, the error log gives a sql error 'Missing column....'

This can occur if your model has changed or you just upgraded the OR Mapper plugin and have generated a new hibernate.hbm.xml file. Before upgrading it is best to export the current database (see the relevant methods in the data store). After exporting start with a new database and re-import the data (through the relevant methods in the datastore).

Editor does not start, ClassNotFoundException on the Editor Plugin

This can happen when the Hibernate libraries can not find the model classes. You can check if you have set the BuddyPolicy in the Manifest.MF of the plugin containing the Hibernate jar files. If not add the following to the Manifest.MF of the plugin containing the Hibernate jar files: Eclipse-BuddyPolicy: dependent

Editor does not start, AssertionFailedException

When you start the editor you get the following exteption (stacktrace truncated):

org.eclipse.core.runtime.AssertionFailedException: assertion failed: 
at org.eclipse.core.runtime.Assert.isTrue(Assert.java:109)
at org.eclipse.core.runtime.Assert.isTrue(Assert.java:95)
at org.eclipse.ui.part.MultiPageEditorPart.setActivePage(MultiPageEditorPart.java:688)
at org.eclipse.ui.part.MultiPageEditorPart.createPartControl(MultiPageEditorPart.java:280)

You probably started the editor with an empty database, the editor does not support this. You should have at least one root object in the database (for example a Library object in the Library tutorial).

Properties are not editable with EMF generated property editor

If you store the .ehb file within the plugin and open the EMF editor using different urls there are situations that the editor opens in read-only mode.

If the url is opened as follows: FileLocator.find(Activator.getDefault().getBundle(), new Path("myfile.ehb"), null). Then the property editor does not allow any modifications.

If however, the editor is opened using a 'file:/' based URL (file://myfile.ehb), then the EMF property editor works as expected.

The first situation can be solved by creating a class similar to this one:

public class CustomAdapterFactoryEditingDomain extends
                AdapterFactoryEditingDomain {
        public CustomAdapterFactoryEditingDomain(AdapterFactory adapterFactory,
                        CommandStack commandStack,
                        Map<Resource, Boolean> resourceToReadOnlyMap) {
                super(adapterFactory, commandStack, resourceToReadOnlyMap);
        }
 
        @Override
        protected boolean isReadOnlyURI(URI uri) {
                return super.isReadOnlyURI(uri)
                                && !uri.fileExtension().equals("ehb");
        }
}

And using an instance of this class as the editingDomain in the initializeEditingDomain() method of the EMF generated XXXEditor class:

protected void initializeEditingDomain() {
        .........
        .........
        editingDomain = new CustomAdapterFactoryEditingDomain(adapterFactory,
commandStack, new HashMap<Resource, Boolean>());
}

Reported and solution by Florian Hackenberger.

Validation exception on enumerate properties when saving the editor content

Symptom: a validation error is thrown (see the console) that certain enumerate fields have not been set.

Cause: the EMF validator incorrectly enforces that the value of an enumerate field should not be the same as the default value.

Solution: is an EMF issue which has been solved (see here). Upgrading EMF to a 2.2 or a later 2.1 release solves this.

Stacktraces when starting Eclipse with already open EMF editor

Symptom: This occurs when keeping an EMF generated editor open when closing eclipse and then starting eclipse again. When starting Eclipse again you see many stack traces in the console with messages like: class not found exception: org/hibernate/proxy/proxy.

Consequence: The editor will open correctly and can be used. The only 'consequence' is that the data is not lazily loaded.

Solution: A solution has been implemented in release 0.2.0.1.

Teneo does not see my changes in the ecore model

Teneo uses the runtime version of the ecore model. The runtime version is present as java code in the generated EPackage implementation class. This runtime ecore can differ from the ecore file when the model code is not regenerated after a change in the ecore file. To let Teneo use the changes in the ecore file the model code needs to be regenerated.

JoinTable name clash

If you have two EReferences between two EClasses then it is possible that you will get a jointable name clash. To prevent this set the PersistenceOptions.JOIN_TABLE_NAMING_STRATEGY to unique (see here).

Back to the top