-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Problem with multi-tenancy (db-level) and TableGenerator
PostPosted: Fri Apr 20, 2012 6:39 am 
Newbie

Joined: Tue Jun 29, 2004 9:16 am
Posts: 7
Location: Germany
I'm trying to use multi-tenancy support with hibernate core 4.0.1. Here an extract from my code to create the session factory:

Code:
Configuration conf = new Configuration();
conf.addResource(getCS5PatchLevelMappingFile(_poolVersion.getPatchLevel()));
conf.setProperty(Environment.DIALECT, MySQL5Dialect.class.getName());
conf.getProperties().put(Environment.MULTI_TENANT, MultiTenancyStrategy.DATABASE);
ServiceRegistryBuilder registryBuilder = new ServiceRegistryBuilder();
registryBuilder.applySettings(conf.getProperties());
registryBuilder.addService( MultiTenantConnectionProvider.class, getPool() );
ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) registryBuilder.buildServiceRegistry();
sessionFactory = conf.buildSessionFactory(serviceRegistry);


However one of my entities uses the "org.hibernate.id.enhanced.TableGenerator" for an ID generator, which should return the ID generated by the table itself. This works ok without using multi-tenancy but runs into a NullPointerException when saving the entity using multi-tenancy:

Code:
java.lang.NullPointerException
   at org.hibernate.engine.transaction.internal.jdbc.JdbcIsolationDelegate.delegateWork(JdbcIsolationDelegate.java:68)
   at org.hibernate.id.enhanced.TableGenerator$1.getNextValue(TableGenerator.java:471)
   at org.hibernate.id.enhanced.OptimizerFactory$NoopOptimizer.generate(OptimizerFactory.java:252)
   at org.hibernate.id.enhanced.TableGenerator.generate(TableGenerator.java:467)
   at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:120)
   at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:204)
   at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55)
   at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:189)
   at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:49)
   at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
   at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:642)
   at org.hibernate.internal.SessionImpl.save(SessionImpl.java:635)
   at org.hibernate.internal.SessionImpl.save(SessionImpl.java:631)


I've looked into the code. The JdbcIsolationDelegate tries to retrieve a ConnectionProvider from org.hibernate.engine.jdbc.internal.JdbcServicesImpl. While JdbcServicesImpl seems to have support for multi-tenancy internally it does not return a connection provider in that case via getConnectionProvider().

Am I doing something wrong here or is this TableGenerator currently incompatible with multi-tenancy? Where would it need to retrieve its connection from?

Thanks for any help!


Top
 Profile  
 
 Post subject: Re: Problem with multi-tenancy (db-level) and TableGenerator
PostPosted: Mon Mar 25, 2013 12:45 pm 
Newbie

Joined: Tue Feb 19, 2008 6:48 am
Posts: 17
I'm having exactly the same problem with Schema Export:

Code:
ERROR: org.hibernate.tool.hbm2ddl.SchemaExport - HHH000231: Schema export unsuccessful
java.lang.NullPointerException
   at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:51)
   at org.hibernate.tool.hbm2ddl.DatabaseExporter.<init>(DatabaseExporter.java:52)
   at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:367)
   at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:304)
   at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:293)
   at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:498)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1750)
   at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:94)


When i activate the multi-tenancy properties in hibernate configuration:

Code:
            <property name="hibernate.hbm2ddl.auto" value="create"/>
            <property name="hibernate.multiTenancy" value="DATABASE" />
            <property name="hibernate.multi_tenant_connection_provider" value="...CustomDataSourceConnectionProvider"/>
            <property name="hibernate.tenant_identifier_resolver" value="..CustomCurrentTenantIdentifierResolver"/>           


I'm a bit lost also...

_________________
João Simas


Top
 Profile  
 
 Post subject: Re: Problem with multi-tenancy (db-level) and TableGenerator
PostPosted: Fri May 17, 2013 8:53 am 
Newbie

Joined: Tue Aug 28, 2007 12:54 pm
Posts: 16
Location: Munich, Germany
remove the hibernate.hbm2ddl.auto setting from your config.
It's not supported for multi-tenancy connections.

_________________
www.tomeicher.de


Top
 Profile  
 
 Post subject: Re: Problem with multi-tenancy (db-level) and TableGenerator
PostPosted: Fri May 17, 2013 8:58 am 
Newbie

Joined: Tue Aug 28, 2007 12:54 pm
Posts: 16
Location: Munich, Germany
and oweise is probably https://hibernate.atlassian.net/browse/HHH-7389 ???

_________________
www.tomeicher.de


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.