0

首先,我使用 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.
}

数据值类:

@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.
}
4

1 回答 1

1

所以你想要一个嵌入式集合?但是正如这个页面清楚地显示的那样,目前 HBase 不支持此功能(支持 MongoDB,但它具有更灵活的数据存储结构来允许它)。您可以拥有一个非实体集合(与所有者保持在同一个 HTable 中),并且您可以拥有一个(非嵌入式)实体集合,但不能拥有嵌入式集合。显然,如果这对您很重要,您可以贡献您的时间来提供支持(我什至会在代码中为您提供要查看的起点)。

没有理由为什么“CollectionTable”应该有所作为......它是 RDBMS 的模式注释(但 JPA 是专门为 RDBMS 设计的)。

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

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

于 2013-04-03T07:42:03.213 回答