gpt4 book ai didi

java - DataNucleus/Kundera 与 HBase 和 ElementCollection - 无法找到具有 null id 的对象

转载 作者:行者123 更新时间:2023-12-01 14:42:43 26 4
gpt4 key购买 nike

首先,我使用 HBase 0.94.5(也尝试过 0.92.2,结果相同)。

我遇到这样的情况:

变量类:

@Entity
@Table(name = "variable", schema = "keyspace@hbase-pu")
public class Variable {
@Id
private String Id;

@Column(name = "Name")
private String Name;

@ElementCollection(fetch = FetchType.EAGER)
//@CollectionTable(name = "datavalues") // Doesn't work with or without.
private List<DataValue> DataValues;

// Getters and setters omitted.
}

DataValue 类:

@Embeddable
public class DataValue {
@Column(name = "Value")
private Object Value;

// Getters and setters omitted.
}

现在,存储它完全没有问题,但是当我想检索它时,爆炸就会发生。抛出此异常:

原因:org.datanucleus.exceptions.NucleusUserException:无法找到 ID 为空的对象!

Exception in thread "main" javax.persistence.PersistenceException: Unable to find the object with a null id!
at org.datanucleus.api.jpa.NucleusJPAHelper.getJPAExceptionForNucleusException(NucleusJPAHelper.java:414)
at org.datanucleus.api.jpa.JPAQuery.getResultList(JPAQuery.java:203)
at Main.main(Main.java:73)
Caused by: org.datanucleus.exceptions.NucleusUserException: Unable to find the object with a null id!
at org.datanucleus.ExecutionContextImpl.findObject(ExecutionContextImpl.java:3441)
at org.datanucleus.store.hbase.fieldmanager.FetchFieldManager.fetchObjectField(FetchFieldManager.java:287)
at org.datanucleus.state.JDOStateManager.replacingObjectField(JDOStateManager.java:2178)
at Variable.jdoReplaceField(Variable.java)
at Variable.jdoReplaceFields(Variable.java)
at org.datanucleus.state.JDOStateManager.replaceFields(JDOStateManager.java:3415)
at org.datanucleus.state.JDOStateManager.replaceFields(JDOStateManager.java:3442)
at org.datanucleus.store.hbase.query.HBaseQueryUtils$2.fetchFields(HBaseQueryUtils.java:270)
at org.datanucleus.state.JDOStateManager.loadFieldValues(JDOStateManager.java:2547)
at org.datanucleus.state.JDOStateManager.initialiseForHollow(JDOStateManager.java:298)
at org.datanucleus.state.ObjectProviderFactoryImpl.newForHollow(ObjectProviderFactoryImpl.java:89)
at org.datanucleus.ExecutionContextImpl.newObjectProviderForHollowPopulated(ExecutionContextImpl.java:1237)
at org.datanucleus.ExecutionContextImpl.findObject(ExecutionContextImpl.java:3053)
at org.datanucleus.store.hbase.query.HBaseQueryUtils.getObjectUsingApplicationIdForResult(HBaseQueryUtils.java:265)
at org.datanucleus.store.hbase.query.HBaseQueryUtils.getObjectsOfType(HBaseQueryUtils.java:194)
at org.datanucleus.store.hbase.query.HBaseQueryUtils.getObjectsOfCandidateType(HBaseQueryUtils.java:93)
at org.datanucleus.store.hbase.query.JPQLQuery.performExecute(JPQLQuery.java:327)
at org.datanucleus.store.query.Query.executeQuery(Query.java:1786)
at org.datanucleus.store.query.Query.executeWithMap(Query.java:1690)
at org.datanucleus.api.jpa.JPAQuery.getResultList(JPAQuery.java:186)
... 1 more

这是因为 ElementCollection,当我删除它时,它会从 HBase 完美地检索变量类。我还尝试了 Kundera 2.4(相同的示例代码),它比 DataNucleus 'enhance' 更容易设置,但它会抛出 Stream 异常。这两个网站都显示了与我上面的代码类似的代码示例,所以我很好奇我在这里做错了什么。

相关pom.xml:

    <dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jpa_2.0_spec</artifactId>
<version>1.1</version>
</dependency>

<dependency>
<groupId>javax.jdo</groupId>
<artifactId>jdo-api</artifactId>
<version>3.0</version>
</dependency>

<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-core</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-api-jpa</artifactId>
<version>3.2.0-release</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-hbase</artifactId>
<version>3.2.0-release</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-enhancer</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>1.1.2</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase</artifactId>
<version>0.94.5</version>
</dependency>


<plugin>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-maven-plugin</artifactId>
<version>3.2.0-release</version>
<configuration>
<api>JPA</api>
<persistenceUnitName>hbase-pu</persistenceUnitName>
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
</plugin>

DataNucleus 的 persistance.xml:

    <persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0">

<!-- JPA tutorial "unit" -->
<persistence-unit name="hbase-pu" transaction-type="RESOURCE_LOCAL">
<provider>org.datanucleus.api.jpa.PersistenceProviderImpl</provider>
<class>Variable</class>
<class>DataValue</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="datanucleus.storeManagerType" value="hbase" />
<property name="datanucleus.ConnectionURL" value="hbase:localhost:2281"/>
<property name="datanucleus.ConnectionUserName" value=""/>
<property name="datanucleus.ConnectionPassword" value=""/>
<property name="datanucleus.autoCreateSchema" value="true"/>
<property name="datanucleus.autoCreateTables" value="true" />
<property name="datanucleus.autoCreateColumns" value="true" />
<property name="datanucleus.validateTables" value="true"/>
<property name="datanucleus.validateConstraints" value="false"/>
<property name="datanucleus.Optimistic" value="false"/>
<property name="datanucleus.Multithreaded" value="true" />
</properties>
</persistence-unit>
</persistence>

昆德拉的persistence.xml:

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
https://raw.github.com/impetus-opensource/Kundera/Kundera-2.0.4/kundera-core/src/test/resources/META-INF/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="hbase-pu">
<provider>com.impetus.kundera.KunderaPersistence</provider>
<properties>
<property name="kundera.nodes" value="localhost" />
<property name="kundera.port" value="2182" />
<property name="kundera.keyspace" value="keyspace" />
<property name="kundera.dialect" value="hbase" />
<property name="kundera.client.lookup.class" value="com.impetus.client.hbase.HBaseClientFactory" />
<property name="kundera.cache.provider.class" value="com.impetus.kundera.cache.ehcache.EhCacheProvider" />
<property name="kundera.cache.config.resource" value="/ehcache-test.xml" />
<property name="kundera.ddl.auto.prepare" value="update" />
</properties>
</persistence-unit>
</persistence>

我对这整件事有点茫然,我有一种感觉,我此时几乎尝试了一切,但不知道如何继续。

-- 请参阅下面的评论。

新变量类:

@Entity
@Table(name = "variable", schema = "keyspace@hbase-pu")
public class Variable {
@Id
private String Id;

@Column(name = "Name")
private String Name;

@ElementCollection(fetch = FetchType.EAGER)
private List<Object> DataValues;

@Column(name = "Value")
@Lob
private Object Value;
// Getters and setters omitted.
}

最佳答案

所以你想要一个嵌入式集合吗?但随后如 this page shows clearly enough ,目前 HBase 不支持这一点(MongoDB 支持,但它有更灵活的数据存储结构来允许它)。您可以拥有非实体的集合(与所有者保留在同一个 HTable 中),也可以拥有(非嵌入)实体的集合,但不能拥有嵌入的集合。显然,如果这对您很重要,您可以贡献您的时间来提供支持(我什至会为您提供代码中的起点以供查看)。

没有理由说“CollectionTable”会有所不同......它是 RDBMS 模式的注释(但 JPA 是专为 RDBMS 设计的)。

PS 1,这个“增强功能”就像在 pom.xml 中添加“插件” block 一样简单。因此,除非您准备好向 DataNucleus 项目表达您的困难是什么,否则他们怎么会知道。

PS 2,如果报告问题,我希望您显示异常+堆栈跟踪,无论涉及什么软件,因为从异常消息中您告诉人们的信息很少。

关于java - DataNucleus/Kundera 与 HBase 和 ElementCollection - 无法找到具有 null id 的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15781113/

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