0

我有一个有 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依赖:

 <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>
4

1 回答 1

1

会认为“值实现类”作为扩展键比你在那里拥有的更有意义(否则怎么知道你在谈论地图的值而不是键?)

于 2012-10-01T07:17:36.397 回答