Datanucleus JDO中的Map属性

时间:2012-09-30 19:00:19

标签: java maven jdo datanucleus

我有一个有Map的类,但是当我尝试预先确定这个实体时,抛出空指针异常。我的代码/设置可能有什么问题?

我的课程:

@PersistenceCapable(detachable="true")
public class MyClassEntity implements MyClass {

    @PrimaryKey
    @Persistent(valueStrategy=IdGeneratorStrategy.NATIVE)
    private String id;

    @Persistent @Join @Element(embedded="true")
    @Extension(vendorName = "datanucleus", key = "implementation-classes", value = "com.company.MySecondClassEntity")
    private Map<String, MySecondClass> map = new HashMap<String, MySecondClass>();

    // Getters and setters here

}

例外:

Exception in thread "main" java.lang.NullPointerException
    at org.datanucleus.store.rdbms.sql.AbstractStatementGenerator.<init>(AbstractStatementGenerator.java:101)
    at org.datanucleus.store.rdbms.sql.AbstractStatementGenerator.<init>(AbstractStatementGenerator.java:139)
    at org.datanucleus.store.rdbms.sql.UnionStatementGenerator.<init>(UnionStatementGenerator.java:153)
    at org.datanucleus.store.rdbms.scostore.RDBMSJoinMapStore.getSQLStatementForGet(RDBMSJoinMapStore.java:770)
    at org.datanucleus.store.rdbms.scostore.RDBMSJoinMapStore.getValue(RDBMSJoinMapStore.java:639)
    at org.datanucleus.store.rdbms.scostore.RDBMSJoinMapStore.putAll(RDBMSJoinMapStore.java:195)
    at org.datanucleus.store.mapped.mapping.MapMapping.postInsert(MapMapping.java:135)
    at org.datanucleus.store.rdbms.request.InsertRequest.execute(InsertRequest.java:520)
    at org.datanucleus.store.rdbms.RDBMSPersistenceHandler.insertTable(RDBMSPersistenceHandler.java:166)
    at org.datanucleus.store.rdbms.RDBMSPersistenceHandler.insertObject(RDBMSPersistenceHandler.java:142)
    at org.datanucleus.state.JDOStateManager.internalMakePersistent(JDOStateManager.java:2377)
    at org.datanucleus.state.JDOStateManager.makePersistent(JDOStateManager.java:2353)
    at org.datanucleus.ObjectManagerImpl.persistObjectInternal(ObjectManagerImpl.java:1896)
    at org.datanucleus.ObjectManagerImpl.persistObjectWork(ObjectManagerImpl.java:1745)
    at org.datanucleus.ObjectManagerImpl.persistObject(ObjectManagerImpl.java:1593)
    at org.datanucleus.api.jdo.JDOPersistenceManager.jdoMakePersistent(JDOPersistenceManager.java:731)
    at org.datanucleus.api.jdo.JDOPersistenceManager.makePersistent(JDOPersistenceManager.java:756)
    at com.mycompany.dao.impl.JDOGenericDao.save(JDOGenericDao.java:63)
    at com.mycompany.dao.Main.main(Main.java:29)

Maven dependecies:

 <dependencies>
    <dependency>
        <groupId>org.datanucleus</groupId>
        <artifactId>datanucleus-core</artifactId>
        <version>3.1.2</version>
    </dependency>
    <dependency>
        <groupId>org.datanucleus</groupId>
        <artifactId>datanucleus-api-jdo</artifactId>
        <version>3.1.2</version>
    </dependency>
    <dependency>
        <groupId>javax.jdo</groupId>
        <artifactId>jdo-api</artifactId>
        <version>3.0.1</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>[1.2, 1.3)</version>
    </dependency>
    <dependency>
        <groupId>org.datanucleus</groupId>
        <artifactId>datanucleus-rdbms</artifactId>
        <version>3.1.2</version>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.21</version>
    </dependency>
</dependencies>

1 个答案:

答案 0 :(得分:1)

本来会认为“value-implementation-classes”作为扩展键比你在那里更有意义(否则怎么知道你在谈论地图的价值而不是键?)