|
Re: [Teneo] createRegisterDataStore followed by deRegisterDataStore fails with NPE [message #1016027 is a reply to message #1016017] |
Mon, 04 March 2013 16:06 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Thanks Rob, HbHelper also has methods to directly generate a mapping, maybe your older version doesn't have it, maybe
you can copy the current content of the generate mapping method.
gr. Martin
On 03/04/2013 04:40 PM, Rob Mising name wrote:
> Hi Martin,
>
> I am currently using an old version of Teneo (1.0.1 ish), I know it's old, but unfortunately I am not able to upgrade at
> this time. I found that if I did something like:
>
> String tempDataStore = "TempName" + System.currentTimeMillis();
> HbDataStore hbDataStore = HbHelper.INSTANCE.createRegisterDataStore(tempDataStore);
> HbHelper.INSTANCE.deRegisterDataStore(tempDataStore);
>
>
> Then the deRegisterDataStore call will throw a NullPointerException. I believe this is because it is always assumed
> that before deRegisterDataStore is called - the code is expecting initialize() to be called on the HbDataStore.
>
> In my case I am not (in fact in the real code it is just using it to generate a hibernate mapping file).
>
> I did have a look at the latest source - and I think this area has changed - so may no longer be a problem.
> (Unfortunately I do not have an environment available at the moment to test against the latest source).
>
> The only way I have found of getting around this is to do something like:
>
>
> if( hbDataStore.getEPackages() == null )
> {
> hbDataStore.setEPackages( new EPackage[]{});
> }
> hbDataStore.setProperties(dataStore.getProperties());
>
> final HbDataStore emfds = HbHelper.INSTANCE.getDataStore(name);
> if( (emfds != null) && !emfds.isInitialized() )
> {
> if( emfds instanceof HbSessionDataStore )
> {
> Configuration configuration = ((HbSessionDataStore)emfds).getConfiguration();
> if( configuration == null )
> {
> configuration = new Configuration();
>
> // Now need to force the configuration to be set
> Field hbSessDS = HbSessionDataStore.class.getDeclaredField("hbConfiguration");
> hbSessDS.setAccessible(true);
> hbSessDS.set(emfds, configuration);
> }
> }
> }
> HbHelper.INSTANCE.deRegisterDataStore(tempDataStore);
>
> I know it is not very nice - but it does seen to work.
>
> I really just thought that I would mention it in case anyone else sees this - as I said - the current code for this area
> looks a fair bit different.
>
> Thanks
>
> Rob
>
>
--
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
|
|
|
|
|
Re: [Teneo] createRegisterDataStore followed by deRegisterDataStore fails with NPE [message #1016147 is a reply to message #1016041] |
Tue, 05 March 2013 09:12 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Rob,
Indeed, see below for the relevant methods in HbHelper for generating a mapping (note this line is also needed:
MappingUtil.registerHbExtensions(extensionManager)).
/**
* Separate utility method, generates a hibernate mapping for a set of epackages and options. The
* hibernate.hbm.xml is returned as a string. The mapping is not registered or used in any other
* way by Elver.
*/
public String generateMapping(EPackage[] epackages, Properties props) {
return generateMapping(epackages, props, ExtensionManagerFactory.getInstance().create());
}
/**
* Separate utility method, generates a hibernate mapping for a set of epackages and options. The
* hibernate.hbm.xml is returned as a string. The mapping is not registered or used in any other
* way by Elver.
*/
public String generateMapping(EPackage[] epackages, Properties props,
ExtensionManager extensionManager) {
MappingUtil.registerHbExtensions(extensionManager);
if (log.isDebugEnabled()) {
log.debug("Generating mapping file passed epackages");
}
// DCB: Use Hibernate-specific annotation processing mechanism. This
// allows use of
// Hibernate-specific annotations.
final PersistenceOptions po = extensionManager.getExtension(PersistenceOptions.class,
new Object[] { props });
final PAnnotatedModel paModel = extensionManager.getExtension(PersistenceMappingBuilder.class)
.buildMapping(epackages, po, extensionManager);
final HibernateMappingGenerator hmg = extensionManager
.getExtension(HibernateMappingGenerator.class);
hmg.setPersistenceOptions(po);
return hmg.generateToString(paModel);
}
gr. Martin
On 03/04/2013 06:05 PM, Rob Mising name wrote:
> Hi Martin,
>
> Is it really as simple as using:
>
> ExtensionManager extensionManager = ExtensionManagerFactory.getInstance().create();
>
> To create the extension manager - and just using that instead of the Temp DataStore?
>
> Thanks
>
> Rob
>
--
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
|
|
|
Powered by
FUDForum. Page generated in 0.02159 seconds