我正在开发一个使用datanucleus作为JPA的WebApp - Provider和Neo4j作为No-SQL数据库。
我的依赖是
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-core</artifactId>
<version>[5.0.0-m1, 5.9)</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-api-jpa</artifactId>
<version>[5.0.0-m1, 5.9)</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>[1.2, 1.3)</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-neo4j</artifactId>
<version>[5.0.0-m1, 5.9)</version>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<version>2.3.0</version>
</dependency>
我的persistence.xml看起来像
<persistence-unit name="neo4j">
<provider>org.datanucleus.api.jpa.PersistenceProviderImpl</provider>
<class>entities.Person</class>
<class>entities.Car</class>
<exclude-unlisted-classes/>
<properties>
<property name="javax.persistence.jdbc.url" value="neo4j:C:\Users\phe\Documents\Neo4j\sampledatanucleus"/>
<!-- <property name="datanucleus.storeManagerType" value="neo4j"/> -->
<property name="datanucleus.storeManagerType" value="neo4j"/>
</properties>
</persistence-unit>
我坚持这样的实体
Person person = new Person(personName, personAge);
Car car = new Car(carName);
car.setOwner(person);
person.getCars().add(car);
em.persist(person);
当持久化实体时,我得到一个例外:
Caused by: org.neo4j.kernel.StoreLockException: Unable to obtain lock on store lock file: C:\Users\phe\Documents\Neo4j\sampledatanucleus\store_lock. Please ensure no other process is using this database, and that the directory is writable (required even for read-only access)
at org.neo4j.kernel.StoreLocker.storeLockException(StoreLocker.java:93)
at org.neo4j.kernel.StoreLocker.checkLock(StoreLocker.java:85)
at org.neo4j.kernel.StoreLockerLifecycleAdapter.start(StoreLockerLifecycleAdapter.java:44)
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:528)
... 153 more
这让我发疯了。当我启动应用程序时,我在perstistence.xml中定义的目录为空。因此,它不可能被另一个进程锁定。然后DataNucleus创建数据库。我可以使用Neo4j Browser访问它。但坚持不起作用。
有什么想法吗?
修改
这是我用来查询的类
@Stateless
public class Manager {
@PersistenceContext(unitName = "neo4j")
private EntityManager em;
public List<Person> queryCache() {
String statement = "Select o from Person o";
Query query = em.createQuery(statement, Person.class);
List<Person> list = query.getResultList();
em.close();
return list;
}
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);
}
}
当单击视图上的相应按钮时,控制器会调用这两个方法。