我试图使文档中的狗/品种示例适用于Neo4j持久性。数据库是正常创建的,但无法刷新数据,至少看起来是这样。我在em.flush()指令(在上面的DogBreedRunner.java类中)中得到错误org.neo4j.graphdb.NotInTransactionException。
我谷歌并搜索了这个问题,但真的无法绕过它。这是我的项目(我没有接触文档中的java类)。
有人能帮忙吗?如果需要其他信息,请告诉我。
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<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">
<persistence-unit name="ogm-jpa-tutorial" transaction-type="JTA">
<!-- Use Hibernate OGM provider: configuration will be transparent -->
<provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
<properties>
<property name="hibernate.ogm.datastore.provider" value="neo4j_embedded" />
<property name="hibernate.ogm.neo4j.database_path" value="C:/Neo4j/NEO4J_HOME/data/graph.db" />
<!-- defines which JTA Transaction we plan to use -->
<property name="hibernate.transaction.jta.platform"
value="org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform"/>
</properties>
</persistence-unit>
</persistence>
Dog.java
package org.hibernate.ogm.examples.gettingstarted.domain;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.TableGenerator;
@Entity
public class Dog {
@Id @GeneratedValue(strategy = GenerationType.TABLE, generator = "dog")
@TableGenerator(
name = "dog",
table = "sequences",
pkColumnName = "key",
pkColumnValue = "dog",
valueColumnName = "seed"
)
public Long getId() { return id; }
public void setId(Long id) { this.id = id; }
private Long id;
public String getName() { return name; }
public void setName(String name) { this.name = name; }
private String name;
@ManyToOne
public Breed getBreed() { return breed; }
public void setBreed(Breed breed) { this.breed = breed; }
private Breed breed;
}
Bread.java
package org.hibernate.ogm.examples.gettingstarted.domain;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import org.hibernate.annotations.GenericGenerator;
@Entity
public class Breed {
@Id @GeneratedValue(generator = "uuid")
@GenericGenerator(name="uuid", strategy="uuid2")
public String getId() { return id; }
public void setId(String id) { this.id = id; }
private String id;
public String getName() { return name; }
public void setName(String name) { this.name = name; }
private String name;
}
DogBreedRunner.java
package org.hibernate.ogm.examples.gettingstarted;
import org.hibernate.ogm.examples.gettingstarted.domain.Breed;
import org.hibernate.ogm.examples.gettingstarted.domain.Dog;
import org.hibernate.ogm.util.impl.Log;
import org.hibernate.ogm.util.impl.LoggerFactory;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.transaction.TransactionManager;
import java.lang.reflect.InvocationTargetException;
public class DogBreedRunner {
private static final String JBOSS_TM_CLASS_NAME = "com.arjuna.ats.jta.TransactionManager";
private static final Log logger = LoggerFactory.make();
public static void main(String[] args) {
TransactionManager tm = getTransactionManager();
//build the EntityManagerFactory as you would build in in Hibernate Core
EntityManagerFactory emf = Persistence.createEntityManagerFactory( "ogm-jpa-tutorial" );
//Persist entities the way you are used to in plain JPA
try {
tm.begin();
logger.infof( "About to store dog and breed" );
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();
logger.infof( "About to commit" );
em.flush();
em.close();
tm.commit();
//Retrieve your entities the way you are used to in plain JPA
logger.infof( "About to retrieve dog and breed" );
tm.begin();
em = emf.createEntityManager();
dina = em.find( Dog.class, dinaId );
logger.infof( "Found dog %s of breed %s", dina.getName(), dina.getBreed().getName() );
em.flush();
em.close();
tm.commit();
emf.close();
} catch ( Exception e ) {
e.printStackTrace();
}
}
public static TransactionManager getTransactionManager() {
try {
Class<?> tmClass = DogBreedRunner.class.getClassLoader().loadClass( JBOSS_TM_CLASS_NAME );
return (TransactionManager) tmClass.getMethod( "transactionManager" ).invoke( null );
} catch ( ClassNotFoundException e ) {
e.printStackTrace();
} catch ( InvocationTargetException e ) {
e.printStackTrace();
} catch ( NoSuchMethodException e ) {
e.printStackTrace();
} catch ( IllegalAccessException e ) {
e.printStackTrace();
}
return null;
}
}
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>hibernate-ogm-documentation-examples</groupId>
<artifactId>HibernateOMG</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<description>Full code for the Getting Started Guide</description>
<url>http://ogm.hibernate.org</url>
<dependencies>
<!-- Hibernate OGM dependency -->
<dependency>
<groupId>org.hibernate.ogm</groupId>
<artifactId>hibernate-ogm-core</artifactId>
<version>4.1.0.Beta5</version>
</dependency>
<!-- standard APIs dependencies - provided in a Java EE container -->
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.ogm</groupId>
<artifactId>hibernate-ogm-neo4j</artifactId>
<version>4.1.0.Beta5</version>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.1_spec</artifactId>
<version>1.0.0.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.1.0</version>
<type>jar</type>
</dependency>
<!-- JBoss Transactions dependency -->
<dependency>
<groupId>org.jboss.jbossts</groupId>
<artifactId>jbossjta</artifactId>
<version>4.16.4.Final</version>
</dependency>
</dependencies>
</project>
例外情况:
org.neo4j.graphdb.NotInTransactionException位于org.neo4j.kernel.impl.persistence.PersistenceManager.getCurrentTransaction(PersistenceManager.java:284)org.neo4j.kernel.impl.persistence.PersistenceManager.getResource(PersistenceManager.java:249)org.neo4j.kernel.impl.PersistenceManager.currentKernelTransactionForReading(PersistenceManager.java:230)org.neo4j.kernel.impl.core.ThreadToStatementContextBridge.transaction(ThreadToStatementContextBridge.java:53)org.neo4j.kernel.impl.core.ThreadToStatementContextBridge.instance(ThreadToStatementContextBridge.java:47)org.neo4j.kernel.impl.core.NodeProxy.setProperty(NodeProxy.java:203)在org.hibernate.ogm.datastore.neo4j.Neo4jDialect.puttupleOperations(Neo4jDialect.java:373)在org.hibernate.ogm.datastore.neo4j.Neo4jDialect.applyooperation(Neo4jDialect.java:355)在org.hibernate.ogm.datastore.neo4j.Neo4jDialect.applyTupleOperations(Neo4jDialect.java:348)在org.hibernate.ogm.ogm.neo4j.Neo4jDialect.Neo4jDialect.updateTuple(Neo4jDialect.java:123)org.hibernate.ogm.persister.OgmEntityPersister.insert(OgmEntityPersister.java:928)org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:104)org.hibernate.engine.spi.ActionQueue.executeactionqueue(ActionQueue.java:463)org.hibernateorg.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:350)org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:56)org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1222)位于org.hibernate.ogm.jpa.spi.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:1335),位于org.hibernate.ogm.jpa.impl.OgmEntityManager.flush(OgmEntityManager.java:119),位于org.hibernate.ogm.examples.gettingstarted.DogBreedRunner.main(DogBreedRunner.java:40)
我把这个问题发到官方论坛,我得到了正确的答案。
private static TransactionManager extractJBossTransactionManager(EntityManagerFactory factory) {
SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) ( (HibernateEntityManagerFactory) factory).getSessionFactory();
return sessionFactory.getServiceRegistry().getService( JtaPlatform.class ).retrieveTransactionManager();
}
顺便说一句,如果使用同一实体管理器处理一行中的多个事务,则需要在事务开始后调用EntityManager#joinTransaction()。
来源:https://forum.hibernate.org/viewtopic.php?f=31
我正在尝试从 JTable 刷新数据。 此方法从数据库中选择数据: 然后我使用这个方法来刷新JTable中的数据: 错误:线程“AWT-EventQueue-0”中的异常 java.lang.ClassCastException: javax.swing.JTable$1 无法强制转换为 javax.swing.table.DefaultTableModel 然后我按下一个按钮来调用这个方法。有人
我正在使用apache ignite缓存oracle表中的静态/引用数据。 我每天晚上11:30都要刷新数据。 null
在uniapp中,某一个页面是统计数据,很多页面随便改什么这个页面就要改变,这个页面是tarbar页面 可以使用拦截器监听路由 但是拦截器是全局的拦截器,我只想写在这一个页面中监听,有什么办法呢?
问题内容: 我对/ 有问题。我的数据表未刷新/更新。我正在使用,根据代码,一切都很好,并且没有任何错误。我也有一个带有分页的表,这就是为什么我使用动作监听器和按钮“上一个”和“下一个”的原因。我正在从其他函数传递到在is中的类中编码的函数 。问题是我填充了包含表数据的数组,但是表不会更新/刷新它。这是我的代码。谢谢前进。 大编辑 旧代码已删除。我添加了新代码,可以帮助您了解我的问题。希望这会有所帮
> 我创建了一个函数,在该函数中我创建了表 我创建了另一个函数,它将我的数据从arraylist发布到我的表中。 到现在为止一切都很好。当我试图更新我的时,问题就出现了。实际上,我打开一个并尝试在列表中添加一个新项。我开始使用新项修改,但之后无法更新表,例如,我真的不知道将放在哪里,以及如何在需要时调用它。 我已经在这个网站上看到了一些问题,但我尝试的没有一个真正适用于我的程序。谢谢你的帮助,对不