hibernate-ogm apache ignite不起作用

时间:2018-07-31 11:40:09

标签: ignite hibernate-ogm

我仍在努力了解OGM / Apache Ignite的全部内容,我在网络上找不到有效的示例。

所以我尝试了这个 pom.xml

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <h2.version>1.4.195</h2.version>
    <ignite.version>2.4.0</ignite.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.hibernate.ogm</groupId>
        <artifactId>hibernate-ogm-ignite</artifactId>
        <version>5.3.1.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.1-api</artifactId>
        <version>1.0.2.Final</version>
    </dependency>
    <dependency>
        <groupId>org.apache.ignite</groupId>
        <artifactId>ignite-core</artifactId>
        <version>${ignite.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.ignite</groupId>
        <artifactId>ignite-spring</artifactId>
        <version>${ignite.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.ignite</groupId>
        <artifactId>ignite-indexing</artifactId>
        <version>${ignite.version}</version>
    </dependency>

    <dependency>
        <groupId>org.jboss.narayana.jta</groupId>
        <artifactId>narayana-jta</artifactId>
        <version>5.4.0.Final</version>
    </dependency>
</dependencies>

Ignite版本2.6.0不适用于hibernate-ogm 5.3.1 Final

TestOGM

package com.example;

import au.com.bueno.issue.issue.model.Breed;
import au.com.bueno.issue.issue.model.Dog;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCluster;
import org.apache.ignite.Ignition;
import org.hibernate.ejb.HibernateEntityManagerFactory;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.transaction.*;

public class TestOgm {
    public static void main(String[] args) throws SystemException, NotSupportedException, HeuristicRollbackException, HeuristicMixedException, RollbackException {
// Connect to the cluster.

    Ignite ignite = Ignition.start();

    ignite.cluster().active(true);
    TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
    EntityManagerFactory emf = Persistence.createEntityManagerFactory(
            "ogm-jpa-tutorial");

    tm.begin();
    EntityManager em = emf.createEntityManager();
    Breed collie = new Breed();
    collie.setName("Collie");
    em.persist(collie);
    Dog dina = new Dog();
    dina.setName("Dina");
    dina.setBreed(collie);
    em.persist(dina);
    Long dinaId = dina.getId();
    System.out.println("dina " + dinaId);
    System.out.println("em = " + em.find(Dog.class, 1L));
    em.flush();
    em.close();
    tm.commit();

}

}

persistence.xml

<?xml version="1.0"?>

http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd”              版本=“ 2.0”>

<persistence-unit name="ogm-jpa-tutorial" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
    <properties>

        <property name="com.arjuna.ats.jta.jtaTMImplementation" value="com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImpl"/>
        <property name="com.arjuna.ats.jta.jtaUTImplementation" value="com.arjuna.ats.internal.jta.transaction.arjunacore.UserTransactionImpl"/>

        <property name="hibernate.ogm.datastore.provider" value="org.hibernate.ogm.datastore.ignite.impl.IgniteDatastoreProvider"/>
        <property name="hibernate.ogm.ignite.configuration_class_name" value="com.example.configuration.ConfigurationBuilder"/>
    </properties>
</persistence-unit>

我在运行它时遇到了这个异常

class org.apache.ignite.IgniteCheckedException: Failed to deserialize object with given class loader: sun.misc.Launcher$AppClassLoader@18b4aac2
at org.apache.ignite.marshaller.jdk.JdkMarshaller.unmarshal0(JdkMarshaller.java:147)
at org.apache.ignite.marshaller.AbstractNodeNameAwareMarshaller.unmarshal(AbstractNodeNameAwareMarshaller.java:94)
at org.apache.ignite.internal.util.IgniteUtils.unmarshal(IgniteUtils.java:9847)
at org.apache.ignite.spi.discovery.tcp.ServerImpl$SocketReader.body(ServerImpl.java:5913)
at org.apache.ignite.spi.IgniteSpiThread.run(IgniteSpiThread.java:62)
Caused by: java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: org.hibernate.boot.registry.internal.StandardServiceRegistryImp

但是,它继续进行,我可以看到生成的输出如下

21:25:39.828 [main] DEBUG 

org.hibernate.event.internal.AbstractSaveEventListener - Generated identifier: 1, using strategy: org.hibernate.ogm.id.impl.OgmTableGenerator
dina 1
em = Dog{id=1, name='Dina', breed=Breed{id='5fc25a4d-c03c-4f2b-b5f9-9812a5c3dedb', name='Collie'}}

我似乎在数据库的任何地方都找不到表Breed或Dog。我试图使持久性存储为true,但我不知道该怎么做,版本2.4.0的api与网站上的内容不相同。 例如,我尝试过

Ignite ignite = Ignition.start();

ignite.cluster().active(true);

它没有帮助。

我将如何启动bin/ignite.sh并使用bin/control.sh --activate为其激活集群,然后使上面的示例对其进行写操作?

感谢与问候 锡

0 个答案:

没有答案