我目前正在尝试在TimerTask (Runnable)中进行hibernate查询。此任务不对数据库进行保存或更新。它只检索一个作业列表。每当我运行这个任务时,我都会得到HibernateException:无法找到当前的JTA事务。
我认为这与以下事实有关:它是从runnable启动的,因为我在这个TimerTask之外使用了相同的查询。
我不能共享我正在使用的代码,因为它是用于工作和专有的。我对这个问题的研究确实引导我找到了Spring的解决方案,但我无法在这项工作中使用Spring。
我会尝试做一些伪代码。
public class JobManager extends TimerTa
我在一个Spring项目中使用JPA (Hibernate),并问自己我的类'BooksHandler‘(即DAO)是否线程安全?
我的的代码:
@Configuration
@EnableTransactionManagement
public class AppConfig {
@Bean
public LocalContainerEntityManagerFactoryBean getEntityManagerFactory() {
LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntit
在Spring 3.1.0中,Hibernate 4中的SessionFactoryUtils.getSession方法发生了什么变化?应该使用什么来代替?sessionFactory.getCurrentSession()一直给我这个异常:
org.hibernate.HibernateException: No Session found for current thread
at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:97)
at o
这个问题类似于以前的。我正在我的Spring事务测试中尝试@Autowire一个Hibernate会话,但是我得到了这个异常:
java.lang.IllegalStateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional ...
这是我的JUnit课程:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"/applic
我有一个简单的java web应用程序,它从数据库接收一些信息,并在web浏览器中显示这些信息。Hibernate用于与servlet和jsp文件中的数据库进行交互。所有的工作都是我想做的,但我不明白一些事情。
数据库很简单-2个表:问答。表格之间的关系是一对多的:一个问题可以有很多答案。
这是java类的代码问答:
Question.java
package app;
import java.util.Set;
public class Question {
Long id = null;
String text = "";
Set<Answ
我有一个独立的线程应用程序。它是一个等待消息的侦听器,当消息到达时,做一些事情,其中我必须将消息保存在DB中。但我遇到了问题,因为如果我运行应用程序并“手动发送消息”,所有事情都能正常工作,但是如果我运行应用程序并等待系统的消息(例如,在它到达后一个小时),当应用程序将保存到它下沉的DB时,我会告诉您:
java.sql.SQLException: Io异常:连接重置或java.sql.BatchUpdateException: Io异常:连接重置
我使用Hibernate 3.2.6和C3p0 0.9.2.1
会议的结构如下:
public final class PersistenceUt
如果我使用getCurrentSession()来获取会话,并且我没有开始事务,而save给出了异常,但是当我使用openSession()来获取会话时,那么在相同的场景中,程序在没有任何exception."hibernate.current_session_context_class“的情况下运行,并且在hibernate configuration file.So中配置了线程,当我使用getCurrentSession()和openSession()时,有什么不同。
Here is the code that gets session using getCurrentSessio
我有一个REST,当我发布一个帖子和一个GET的时候,我得到了这个异常:
SEVERE: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container
java.lang.IllegalStateException: Transaction already active
at org.hibernate.engine.transaction.internal.TransactionImpl.begin(TransactionImpl.java:52)
at o
我需要知道Hibernate的会话是否是线程安全的。但是很明显,每个线程都会附加一个新的会话来执行。但我的问题是,如果我在一个线程中更新了一个实体的一些值,那么在同一时间执行期间,这会在其他线程中反映出来吗?
我的问题是,当我从两个线程顺序启动更新时,值被正确更新,但当我几乎完全启动更新时,它就失败了。
例如。表的当前阶段。
ID NAME MARKS
------- --------- --------
1 John 54
我试着做以下事情:
Student student = session.load(Student.class, 1);
我正在写一个简单的项目,一个用Swing编写的商业应用程序,使用Hibernate作为后端。我来自Spring,这给了我使用hibernate和事务的简单方法。不管怎样,我设法让Hibernate工作了。昨天,当我写一些代码从数据库中删除一个bean时,我得到了这样的结果:
org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
删除代码很简单:
Session sess = HibernateUtil.getSession();
Tra
如果我打开一个事务,并将可能会将OLE抛出一个try-catch块的代码放入其中,那么我必须重新启动事务吗?我的回答是肯定的,但我似乎找不到任何证实.
我的代码基本上如下所示:
//start a hibernate transaction here
try
{
//do things that are very likely to throw OLE
}
catch (Exception exc)
{
//just log it and do nothing else
}
//do something else that needs a hibernate session h
我希望我的read方法不使用事务,因为这根本不需要,我只使用@ transaction标记创建/更新方法。但我该怎么做?我有一个非常基本的Spring配置等等..。
在我的DAO中注入了SessionFactory,在每种方法中我都调用了sessionFactory.getCurrentSession().doQueryStuff();
然而,这会导致以下错误:
org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of
我在EJB3和通配符10上运行Hibernate 5,有些请求在第一次Hibernate调用时失败
org.hibernate.HibernateException: Current transaction is not in progress
当我试图调用sessionFactory().getCurrentSession()方法时。(使用JTATransactionManager管理hibernate.cfg.xml)中的事务)
我经常碰到这些术语。他们是两个人的区别吗?
在以下Java代码中,该方法是线程安全的:
class Counter {
private int i = 0;
public synchronized void inc() {
i++;
}
}
在Hibernate中SessionFactory和会话的上下文中,
SessionFactory (org.hibernate.SessionFactory) - A thread-safe
Session (org.hibernate.Session) - A single-threaded, short-l