Question

EDIT-This is the answer The code I mistakenly used was for editing metadata. For reading it, use the following:

pmf.getMetadata(Machineclass.getName()).getTable()

I've been doing this for a long time using previous datanucleus versions but I'm not sure why isn't it working anymore with v3.2

This code doesn't work because the getMetaDataForClass method now always returns null !

NucleusJDOHelper.getMetaDataForClass(pmf, clazz).getTable()

Where pmf is the PersistenceManagerFactory and clazz is a Class<?> object representing the class type of the PC (i.e. persistence capable) object which I need to retrieve the table name for.

I'm only using annotations to define my mappings.

To create my PersistenceManagerFactory, I'm using the following code:

JDOHelper.getPersistenceManagerFactory(new FileInputStream(filePath));

Where filePath is a path to a properties file with enough data that has been used for a long time without any change.

EDIT: Thanks to Neil's answer, I switched to using the following code sequence:

JDOMetadata md = pmf.newMetadata();
PackageMetadata pmd = md.newPackageMetadata(clazz.getPackage());
ClassMetadata cmd = pmd.newClassMetadata(clazz);
return cmd.getTable();

I made sure that the class I'm inspecting is having the proper metadata

@PersistenceCapable(table = "machine_table", detachable = "true", cacheable = "true")
public class Machine {

Now cmd.getTable() returns null too !

Was it helpful?

Solution

Why use some internal (unsupported?) API when JDO has had a Metadata API since JDO v2.x IIRC? This one here http://www.datanucleus.org/products/accessplatform_3_3/jdo/metadata_api.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top