gpt4 book ai didi

java - Datanucleus JDO 中的映射属性

转载 作者:行者123 更新时间:2023-12-01 15:08:21 30 4
gpt4 key购买 nike

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

我的类(class):

@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):

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>

最佳答案

我会认为“值实现类”作为扩展键比您在那里拥有的更有意义(否则如何知道您正在谈论映射的值而不是键?)

关于java - Datanucleus JDO 中的映射属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12664086/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com