Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [CDO/Teneo] How to create HibernateStore programatically? / org.hibernate.MappingException: Could no
[CDO/Teneo] How to create HibernateStore programatically? / org.hibernate.MappingException: Could no [message #1009767] Fri, 15 February 2013 17:02 Go to next message
Kris Missing name is currently offline Kris Missing nameFriend
Messages: 47
Registered: July 2009
Member
Hi,

I would like to run the cdo server in embedded mode as part of an rcp
setup, as described here:
http://wiki.eclipse.org/Run_a_CDO_container_inside_eclipse_runtime

Since Hibernate Store is used I am trying to create an IStore that is a
HibernateStore implementation.

I am wondering if the code below - especially the createStore-method of
CDOServerInitializer is the correct procedure to create it, since
classes of "internal" packages are used.

Furthermore, the execution fails in the step adding the repository with
this exception:

org.hibernate.MappingException: Could not determine type for:
org.eclipse.emf.cdo.common.lob.CDOBlob, at table: mytable, for columns:
[org.hibernate.mapping.Column(content)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:304)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:288)
at org.hibernate.mapping.Property.isValid(Property.java:238)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:468)
at org.hibernate.mapping.RootClass.validate(RootClass.java:270)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1290)
at
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1732)
at
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1778)
at
org.eclipse.emf.cdo.server.internal.hibernate.HibernateStore.getHibernateSessionFactory(HibernateStore.java:260)
at
org.eclipse.emf.cdo.server.internal.hibernate.HibernateStoreAccessor.beginHibernateSession(HibernateStoreAccessor.java:194)
at
org.eclipse.emf.cdo.server.internal.hibernate.HibernateStoreAccessor.getHibernateSession(HibernateStoreAccessor.java:268)
at
org.eclipse.emf.cdo.server.internal.hibernate.HibernateStoreAccessor.queryResources(HibernateStoreAccessor.java:495)
at
org.eclipse.emf.cdo.spi.server.StoreAccessorBase.readResourceID(StoreAccessorBase.java:212)
at
org.eclipse.emf.cdo.internal.server.Repository.readRootResource(Repository.java:1770)
at
org.eclipse.emf.cdo.internal.server.Repository.doActivate(Repository.java:1870)
at org.eclipse.net4j.util.lifecycle.Lifecycle.activate(Lifecycle.java:76)
at
org.eclipse.net4j.util.lifecycle.LifecycleUtil.activate(LifecycleUtil.java:114)
at
org.eclipse.net4j.util.lifecycle.LifecycleUtil.activate(LifecycleUtil.java:104)
at
org.eclipse.emf.cdo.server.CDOServerUtil.addRepository(CDOServerUtil.java:208)
...

Do I have to register a special type mapping for the CDOBlob to e.g.
java.sql.Blob? Or is it because of a wrong approach to create the
HibernateStore?

Thanks
Kris


-------------------------------------


package com.project.persistence.hibernate.impl;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import org.eclipse.emf.cdo.net4j.CDONet4jSessionConfiguration;
import org.eclipse.emf.cdo.net4j.CDONet4jUtil;
import org.eclipse.emf.cdo.server.CDOServerUtil;
import org.eclipse.emf.cdo.server.IRepository;
import org.eclipse.emf.cdo.server.IStore;
import
org.eclipse.emf.cdo.server.hibernate.internal.teneo.TeneoHibernateMappingProvider;
import org.eclipse.emf.cdo.server.internal.hibernate.HibernateStore;
import org.eclipse.net4j.Net4jUtil;
import org.eclipse.net4j.connector.IConnector;
import org.eclipse.net4j.jvm.IJVMAcceptor;
import org.eclipse.net4j.jvm.IJVMConnector;
import org.eclipse.net4j.jvm.JVMUtil;
import org.eclipse.net4j.util.container.ContainerUtil;
import org.eclipse.net4j.util.container.IManagedContainer;
import org.eclipse.net4j.util.om.OMPlatform;
import org.eclipse.net4j.util.om.log.PrintLogHandler;
import org.eclipse.net4j.util.om.trace.PrintTraceHandler;

/**
* TODO: class comment
*
* @author Author, Company
*/
public class CDOServerInitializer {

// protected static final String CONNECTION_ADDRESS =
"localhost:2036"; //$NON-NLS-1$

private final String repositoryName;
private final String resourceName;

private IManagedContainer container;

private IRepository repository;

private IJVMConnector connector;

private IJVMAcceptor acceptor;

private CDONet4jSessionConfiguration sessionConfiguration;

public CDOServerInitializer(final String repositoryName, final
String resourceName) {
this.repositoryName = repositoryName;
this.resourceName = resourceName;
}

/**
* Initializes the connection and creates a {@link
CDOSessionConfiguration} which is stored in a member of this
* class.
*/
public void initialize() {
OMPlatform.INSTANCE.setDebugging(true);
OMPlatform.INSTANCE.addLogHandler(PrintLogHandler.CONSOLE);
OMPlatform.INSTANCE.addTraceHandler(PrintTraceHandler.CONSOLE);

this.container = createContainer();
initializeAcceptor(container);

final IStore store = createStore();
this.repository = createRepository(repositoryName, store);

addRepository(container, repository);

final IConnector connector = createConnector(container);
this.sessionConfiguration = createSessionConfiguration(connector);

}

private IManagedContainer createContainer() {
// Prepare container
final IManagedContainer container =
ContainerUtil.createContainer();
Net4jUtil.prepareContainer(container); // Register Net4j factories
// TCPUtil.prepareContainer(container); // Register TCP factories
JVMUtil.prepareContainer(container);
CDONet4jUtil.prepareContainer(container); // Register CDO factories
container.activate();

return container;
}

private IRepository createRepository(final String repositoryName,
final IStore store) {
final Map<String, String> props = new HashMap<String, String>();
props.put("supportingAudits", "false");
// props.put(Props.SUPPORTING_REVISION_DELTAS, "false");
// props.put(Props.CURRENT_LRU_CAPACITY, "10000");
// props.put(Props.REVISED_LRU_CAPACITY, "10000");
return CDOServerUtil.createRepository(repositoryName, store,
props);
}

private IStore createStore() {

final Properties teneoProps = new Properties();

teneoProps.put("teneo.mapping.cascade_policy_on_non_containment",
"PERSIST,MERGE");
teneoProps.put("teneo.mapping.inheritance", "JOINED");
teneoProps.put("teneo.mapping.add_index_for_fk", "true");
teneoProps.put("teneo.naming.default_id_column", "id");
final TeneoHibernateMappingProvider mappingProvider = new
TeneoHibernateMappingProvider();
mappingProvider.setMappingProviderProperties(teneoProps);

final Properties props = new Properties();
props.put("hibernate.hbm2ddl.auto", "update");
props.put("hibernate.show_sql", "true");
props.put("hibernate.connection.pool_size", "10");
props.put("hibernate.cache.provider_class",
"org.hibernate.cache.HashtableCacheProvider");
props.put("hibernate.dialect",
"org.hibernate.dialect.HSQLDialect");
props.put("hibernate.connection.driver_class",
"org.hsqldb.jdbcDriver");
props.put("hibernate.connection.url",
"jdbc:hsqldb:hsql://localhost:9002/projectdb");
props.put("hibernate.connection.username", "sa");
props.put("hibernate.connection.password", "");

final HibernateStore store = new
HibernateStore(mappingProvider, props);

return store;
}

private IConnector createConnector(final IManagedContainer container) {
this.connector = JVMUtil.getConnector(container, "default");
return connector;
}

private void addRepository(final IManagedContainer container, final
IRepository repository) {
CDOServerUtil.addRepository(container, repository);
}

private void initializeAcceptor(final IManagedContainer container) {
// initialize acceptor
this.acceptor = JVMUtil.getAcceptor(container, "default");
}

private CDONet4jSessionConfiguration
createSessionConfiguration(final IConnector connector) {

final CDONet4jSessionConfiguration config =
CDONet4jUtil.createNet4jSessionConfiguration();
config.setConnector(connector);
config.setRepositoryName(repositoryName);

return config;
}

/**
* @return
*/
public CDONet4jSessionConfiguration getSessionConfiguration() {
return this.sessionConfiguration;
}

public String getResourceName() {
return this.resourceName;
}

/**
* @return
*/
public IJVMAcceptor getAcceptor() {
return this.acceptor;
}

/**
* @return
*/
public IJVMConnector getConnector() {
return this.connector;
}

/**
* @return
*/
public IRepository getRepository() {
return this.repository;
}

}
Re: [CDO/Teneo] How to create HibernateStore programatically? / org.hibernate.MappingException: Coul [message #1012855 is a reply to message #1009767] Fri, 22 February 2013 10:36 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5339
Registered: July 2009
Senior Member
Hi KW,
Sorry I seemed to have missed your post (normally we answer the same day here at the EMF newsgroup...).

This can happen because of class loading problems, so hibernate can't find the org.eclipse.emf.cdo.common.lob.CDOBlob
type. Did you install the hibernate plugin from the elver.org update site?
Can you see if you can refer to the CDOBlob in the code below (as a test at compile time), can you check/validate the
runtime plugins?

gr. Martin

On 02/15/2013 06:02 PM, KW wrote:
> Hi,
>
> I would like to run the cdo server in embedded mode as part of an rcp setup, as described here:
> http://wiki.eclipse.org/Run_a_CDO_container_inside_eclipse_runtime
>
> Since Hibernate Store is used I am trying to create an IStore that is a HibernateStore implementation.
>
> I am wondering if the code below - especially the createStore-method of CDOServerInitializer is the correct procedure to
> create it, since classes of "internal" packages are used.
>
> Furthermore, the execution fails in the step adding the repository with this exception:
>
> org.hibernate.MappingException: Could not determine type for: org.eclipse.emf.cdo.common.lob.CDOBlob, at table: mytable,
> for columns: [org.hibernate.mapping.Column(content)]
> at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:304)
> at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:288)
> at org.hibernate.mapping.Property.isValid(Property.java:238)
> at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:468)
> at org.hibernate.mapping.RootClass.validate(RootClass.java:270)
> at org.hibernate.cfg.Configuration.validate(Configuration.java:1290)
> at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1732)
> at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1778)
> at org.eclipse.emf.cdo.server.internal.hibernate.HibernateStore.getHibernateSessionFactory(HibernateStore.java:260)
> at
> org.eclipse.emf.cdo.server.internal.hibernate.HibernateStoreAccessor.beginHibernateSession(HibernateStoreAccessor.java:194)
> at
> org.eclipse.emf.cdo.server.internal.hibernate.HibernateStoreAccessor.getHibernateSession(HibernateStoreAccessor.java:268)
> at
> org.eclipse.emf.cdo.server.internal.hibernate.HibernateStoreAccessor.queryResources(HibernateStoreAccessor.java:495)
> at org.eclipse.emf.cdo.spi.server.StoreAccessorBase.readResourceID(StoreAccessorBase.java:212)
> at org.eclipse.emf.cdo.internal.server.Repository.readRootResource(Repository.java:1770)
> at org.eclipse.emf.cdo.internal.server.Repository.doActivate(Repository.java:1870)
> at org.eclipse.net4j.util.lifecycle.Lifecycle.activate(Lifecycle.java:76)
> at org.eclipse.net4j.util.lifecycle.LifecycleUtil.activate(LifecycleUtil.java:114)
> at org.eclipse.net4j.util.lifecycle.LifecycleUtil.activate(LifecycleUtil.java:104)
> at org.eclipse.emf.cdo.server.CDOServerUtil.addRepository(CDOServerUtil.java:208)
> ...
>
> Do I have to register a special type mapping for the CDOBlob to e.g. java.sql.Blob? Or is it because of a wrong approach
> to create the HibernateStore?
>
> Thanks
> Kris
>
>
> -------------------------------------
>
>
> package com.project.persistence.hibernate.impl;
>
> import java.util.HashMap;
> import java.util.Map;
> import java.util.Properties;
>
> import org.eclipse.emf.cdo.net4j.CDONet4jSessionConfiguration;
> import org.eclipse.emf.cdo.net4j.CDONet4jUtil;
> import org.eclipse.emf.cdo.server.CDOServerUtil;
> import org.eclipse.emf.cdo.server.IRepository;
> import org.eclipse.emf.cdo.server.IStore;
> import org.eclipse.emf.cdo.server.hibernate.internal.teneo.TeneoHibernateMappingProvider;
> import org.eclipse.emf.cdo.server.internal.hibernate.HibernateStore;
> import org.eclipse.net4j.Net4jUtil;
> import org.eclipse.net4j.connector.IConnector;
> import org.eclipse.net4j.jvm.IJVMAcceptor;
> import org.eclipse.net4j.jvm.IJVMConnector;
> import org.eclipse.net4j.jvm.JVMUtil;
> import org.eclipse.net4j.util.container.ContainerUtil;
> import org.eclipse.net4j.util.container.IManagedContainer;
> import org.eclipse.net4j.util.om.OMPlatform;
> import org.eclipse.net4j.util.om.log.PrintLogHandler;
> import org.eclipse.net4j.util.om.trace.PrintTraceHandler;
>
> /**
> * TODO: class comment
> *
> * @author Author, Company
> */
> public class CDOServerInitializer {
>
> // protected static final String CONNECTION_ADDRESS = "localhost:2036"; //$NON-NLS-1$
>
> private final String repositoryName;
> private final String resourceName;
>
> private IManagedContainer container;
>
> private IRepository repository;
>
> private IJVMConnector connector;
>
> private IJVMAcceptor acceptor;
>
> private CDONet4jSessionConfiguration sessionConfiguration;
>
> public CDOServerInitializer(final String repositoryName, final String resourceName) {
> this.repositoryName = repositoryName;
> this.resourceName = resourceName;
> }
>
> /**
> * Initializes the connection and creates a {@link CDOSessionConfiguration} which is stored in a member of this
> * class.
> */
> public void initialize() {
> OMPlatform.INSTANCE.setDebugging(true);
> OMPlatform.INSTANCE.addLogHandler(PrintLogHandler.CONSOLE);
> OMPlatform.INSTANCE.addTraceHandler(PrintTraceHandler.CONSOLE);
>
> this.container = createContainer();
> initializeAcceptor(container);
>
> final IStore store = createStore();
> this.repository = createRepository(repositoryName, store);
>
> addRepository(container, repository);
>
> final IConnector connector = createConnector(container);
> this.sessionConfiguration = createSessionConfiguration(connector);
>
> }
>
> private IManagedContainer createContainer() {
> // Prepare container
> final IManagedContainer container = ContainerUtil.createContainer();
> Net4jUtil.prepareContainer(container); // Register Net4j factories
> // TCPUtil.prepareContainer(container); // Register TCP factories
> JVMUtil.prepareContainer(container);
> CDONet4jUtil.prepareContainer(container); // Register CDO factories
> container.activate();
>
> return container;
> }
>
> private IRepository createRepository(final String repositoryName, final IStore store) {
> final Map<String, String> props = new HashMap<String, String>();
> props.put("supportingAudits", "false");
> // props.put(Props.SUPPORTING_REVISION_DELTAS, "false");
> // props.put(Props.CURRENT_LRU_CAPACITY, "10000");
> // props.put(Props.REVISED_LRU_CAPACITY, "10000");
> return CDOServerUtil.createRepository(repositoryName, store, props);
> }
>
> private IStore createStore() {
>
> final Properties teneoProps = new Properties();
>
> teneoProps.put("teneo.mapping.cascade_policy_on_non_containment", "PERSIST,MERGE");
> teneoProps.put("teneo.mapping.inheritance", "JOINED");
> teneoProps.put("teneo.mapping.add_index_for_fk", "true");
> teneoProps.put("teneo.naming.default_id_column", "id");
> final TeneoHibernateMappingProvider mappingProvider = new TeneoHibernateMappingProvider();
> mappingProvider.setMappingProviderProperties(teneoProps);
>
> final Properties props = new Properties();
> props.put("hibernate.hbm2ddl.auto", "update");
> props.put("hibernate.show_sql", "true");
> props.put("hibernate.connection.pool_size", "10");
> props.put("hibernate.cache.provider_class", "org.hibernate.cache.HashtableCacheProvider");
> props.put("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
> props.put("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver");
> props.put("hibernate.connection.url", "jdbc:hsqldb:hsql://localhost:9002/projectdb");
> props.put("hibernate.connection.username", "sa");
> props.put("hibernate.connection.password", "");
>
> final HibernateStore store = new HibernateStore(mappingProvider, props);
>
> return store;
> }
>
> private IConnector createConnector(final IManagedContainer container) {
> this.connector = JVMUtil.getConnector(container, "default");
> return connector;
> }
>
> private void addRepository(final IManagedContainer container, final IRepository repository) {
> CDOServerUtil.addRepository(container, repository);
> }
>
> private void initializeAcceptor(final IManagedContainer container) {
> // initialize acceptor
> this.acceptor = JVMUtil.getAcceptor(container, "default");
> }
>
> private CDONet4jSessionConfiguration createSessionConfiguration(final IConnector connector) {
>
> final CDONet4jSessionConfiguration config = CDONet4jUtil.createNet4jSessionConfiguration();
> config.setConnector(connector);
> config.setRepositoryName(repositoryName);
>
> return config;
> }
>
> /**
> * @return
> */
> public CDONet4jSessionConfiguration getSessionConfiguration() {
> return this.sessionConfiguration;
> }
>
> public String getResourceName() {
> return this.resourceName;
> }
>
> /**
> * @return
> */
> public IJVMAcceptor getAcceptor() {
> return this.acceptor;
> }
>
> /**
> * @return
> */
> public IJVMConnector getConnector() {
> return this.connector;
> }
>
> /**
> * @return
> */
> public IRepository getRepository() {
> return this.repository;
> }
>
> }


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Previous Topic:ArrayOutOfBoundsException: -14
Next Topic:question about default namespaces
Goto Forum:
  


Current Time: Tue Nov 25 21:25:20 GMT 2014

Powered by FUDForum. Page generated in 0.02126 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software