Search code examples
neo4jjpa-2.1hibernate-ogm

Hibernate OGM Neo4j -Unable to access TransactionManager


I trying to build a JSF WebApplication using Neo4j as No-SQL-Databasing. I want to access Neo4j via Hibernate.

My dependencies are

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.hibernate.ogm</groupId>
            <artifactId>hibernate-ogm-bom</artifactId>
            <version>5.0.1.Final</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>org.hibernate.ogm</groupId>
        <artifactId>hibernate-ogm-neo4j</artifactId>
    </dependency>

My entities look like the following

@Entity
public class Person implements Serializable {

 private static final long serialVersionUID = 1L;

 @Id
 @GeneratedValue(generator = "uuid")
 @GenericGenerator(name = "uuid", strategy = "uuid2")
 private String id;

 private String name;

 private Double age;

 @OneToMany(fetch = FetchType.EAGER, mappedBy = "owner", cascade = CascadeType.PERSIST)
 private Set<Car> cars = new HashSet<>();
 ...

I save them within in the following class

@Stateless
public class StorageManager {

 @PersistenceContext(unitName = "neo4j")
 private EntityManager em;

 public void savePerson(Person p) {
    em.persist(p);
 }

 public void saveCar(Car c){
    em.persist(c);
 }

 public void save(String personName, Double personAge, String carName) {
    Person person = new Person(personName, personAge);
    Car car = new Car(carName);
    car.setOwner(person);
    person.getCars().add(car);
    em.persist(person);
 }

My Persistence Unit

<persistence-unit name="mongo-ogm" transaction-type="JTA">
    <provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
    <class>entities.Person</class>
    <class>entities.Car</class>
    <exclude-unlisted-classes>true</exclude-unlisted-classes>

    <properties>
        <property name="hibernate.ogm.datastore.provider" value="neo4j_embedded" />
        <property name="hibernate.ogm.neo4j.database_path" value="C:\Users\phe\Documents\Neo4j\sample" />
    </properties>
</persistence-unit>

When I deploy the WebApp on my Wildlfy 9 and want to save Data I get an Exception

org.hibernate.resource.transaction.backend.jta.internal.JtaPlatformInaccessibleException: Unable to access TransactionManager or UserTransaction to make physical transaction delegate

Researches in the internet ended with no result. There are only a few tutorials. I have tried it with and without transaction-type="JTA" .

Have you any ideas?


Solution

  • I found the solution. As I am deploying to Wildlfy I can add the following to my Persistence Unit.

    <property name="hibernate.transaction.jta.platform" value="JBossAS" />
    

    This works for me.