我尝试使用 Neo4j 作为 No-SQL-Databasing 构建 JSF WebApplication。我想通过 Hibernate 访问 Neo4j。
我的依赖是
<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>
我的实体如下所示
@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<>();
...
我将它们保存在以下课程中
@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);
}
我的坚持单位
<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>
当我在 Wildlfy 9 上部署 WebApp 并想要保存数据时,出现异常
org.hibernate.resource.transaction.backend.jta.internal.JtaPlatformInaccessibleException: Unable to access TransactionManager or UserTransaction to make physical transaction delegate
互联网上的研究没有结果。只有几个教程。我已经尝试过使用和不使用 transaction-type="JTA" 。
你有什么想法吗?