- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个使用 Spring 和 Hibernate 的项目。
使用 hibernate 进行插入后,即使我调用了 session.flush 方法,我也看不到 jdbc sql 中的数据。知道为什么会发生这种情况吗?
我的配置是这样的:
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="packagesToScan">
<list>
<value>ro.asf.capone.common.model</value>
</list>
</property>
<property name="dataSource" ref="dataSource"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${agency.hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${agency.hibernate.show_sql}</prop>
<prop key="hibernate.format_sql">${agency.hibernate.format_sql}</prop>
<prop key="hibernate.jdbc.batch_size">100</prop>
<prop key="hibernate.jdbc.batch_versioned_data">true</prop>
<prop key="hibernate.jdbc.use_streams_for_binary">true</prop>
<prop key="hibernate.order_updates">true</prop>
<prop key="hibernate.connection.release_mode">auto</prop>
<prop key="hibernate.connection.autocommit">true</prop>
<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.use_structured_entries">true</prop>
<prop key="hibernate.cache.provider_configuration_file_resource_path">ehcache.xml</prop>
<prop key="hibernate.generate_statistics">false</prop>
<prop key="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</prop>
<prop key="hibernate.query.factory_class">org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory</prop>
</props>
</property>
<property name="entityInterceptor" ref="auditInterceptor" />
</bean>
我也尝试过<prop key="hibernate.connection.autocommit">false</prop>
得到相同的结果。
数据源是hiraki ds,但我尝试过bonecp,结果相同。
@Bean
public DataSource dataSource() {
final HikariDataSource dataSource = new HikariDataSource();
// dataSource.setAutoCommit(false);
dataSource.setDriverClassName(jdbcDriver);
dataSource.setJdbcUrl(jdbcUrl);
dataSource.setUsername(jdbcUsername);
dataSource.setPassword(jdbcPassword);
dataSource.setIdleTimeout(60000);
dataSource.setMinimumIdle(0);
dataSource.setMaximumPoolSize(2);
return dataSource;
}
我正在使用的代码是:
final AuditUsers typ = new AuditUsers();
typ.setEntityId(1l);
typ.setLevel(29);
final Serializable typid = getSession().save(typ);
System.out.println(">>>>>>>>>>>>>> id: " + typid);
getSession().flush();
getSession().clear();
final String sqltyp = "select * from AUDIT_USERS where id = " + typid;
try(Connection con = getConnection(); Statement stm = con.createStatement()){
System.out.println("!!!" + con.getAutoCommit());
final ResultSet rs = stm.executeQuery(sqltyp);
while(rs.next()){
System.out.println("RS filename: " + rs.getString("ENTITY_ID"));
}
}catch (final Exception e) {
e.printStackTrace();
}
而且我没有得到 rs 的下一个值。
如果我使用 doWork 方法,结果集会有值,但我不想这样使用它。
getSession().doWork(new Work() {
@Override
public void execute(final Connection connection) throws SQLException {
final Statement stm = connection.createStatement();
final ResultSet rs = stm.executeQuery(sqltyp);
while(rs.next()){
System.out.println("RS filename: " + rs.getString("ENTITY_ID"));
}
}
});
我有一个 HibernateDAOSupport 类,用于设置访问从 spring 配置 xml 设置的数据源和 sessionfactory:
public abstract class HibernateDAOSupport {
private SessionFactory sessionFactory;
private DataSource dataSource;
public SessionFactory getSessionFactory() {
return sessionFactory;
}
public void setSessionFactory(final SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
public DataSource getDataSource() {
return dataSource;
}
public void setDataSource(final DataSource dataSource) {
this.dataSource = dataSource;
}
public void setDs(final DataSource dataSource) {
this.dataSource = dataSource;
}
public Session getSession() {
return sessionFactory.getCurrentSession();
}
public Connection getConnection() throws SQLException {
return dataSource.getConnection();
}
}
和 xml:
<bean id="hibernateDAO" class="ro.asf.capone.server.dao.HibernateDAOSupport" abstract="true">
<property name="sessionFactory" ref="sessionFactory" />
<property name="dataSource" ref="dataSource" />
</bean>
最佳答案
我通过更改 getConnection
找到了解决方案实现于HibernateDAOSupport
类:
public Connection getConnection(){
return org.springframework.jdbc.datasource.DataSourceUtils.getConnection(dataSource);
}
感谢 M. Deinum 指出数据源提供了一个新连接,但使用的连接不是同一个。我的印象是单个连接跨越一个事务。
关于java - JDBC 查询看不到同一事务上的 session.flush 修改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34134947/
我一直在尝试处理一个类项目,在该项目中我必须设置一个面向 GUI 的转换程序,并且我试图将数据从我的类的方法传递到 ActionListener,但监听器是告诉我文本字段不存在。它位于同一个包和类中,
我在服务器上有两个版本的 PHP(Centos 6.8) - 5.6 和 7.1 我的 Nginx 使用 php7.1,它不是默认的 PHP 解释器。 经过一番与 yum 的斗争后,我安装了 php7
我正在尝试为 BEAGLE 安装 OpenCL .首先,我下载了 intel_sdk_for_opencl_applications_2020.3.494.tar.gz 来自 here .然后我解压并
我想知道为什么我在 controlPanel 中看不到 topPanel 这是我的代码: import java.awt.BorderLayout; import java.awt.Color; im
在我的 urls.py 中,我有以下内容: urlpatterns = patterns('', # Examples: #url(r'^$', 'welcome_page.home'
非常感谢大家的帮助! 在 GetProductByID 下,我收到一条错误消息“int does not contain a definition for FirstOrDefault”。 using
1) 我已经通过 my computuer -> System variables; 设置了变量 CLASSPATH 2) 重新启动控制台并键入 echo %CLASSPATH%,CLASSPATH
我已经看过这篇文章了PHP doesn't see mysql extension ,但这对我没有帮助。 我使用: Windows Seven(在虚拟机中为 32 位,在真实电脑上为 64 位) 带
当我尝试通过输入 python3 来验证 Python3 是否可以看到 Django 时其次是 import django进入终端(这样我就可以打印 Django 的版本号),我得到以下错误: Tra
我已经使用 easy_install 安装了 pygraphviz但是当我启动 python 时出现错误: >>>import pygraphviz as pgv Traceback (most re
在向 Microsoft 报告之前,我想在这里问一下。我有一个问题,我无法看到我的 WinUI 3 应用程序的实时可视化树。我什至看不到应用程序内工具栏。我可以在 WPF 和 UWP 应用程序中看到,
我对缺乏基本的了解和 内。 我希望看到 39 个 svg 子元素,100 像素高,每个子元素中都有清晰的文本。 http://jsfiddle.net/pn5sj8ge/ 最佳答案 发生这种情况的原因
我正在尝试设置一个新的持续集成服务器,该服务器利用 Phing 和 PHPUnit 自动运行测试用例。 我已经用 Pear 安装了 Phing: pear channel-discover pear.
lua -e "print(package.path)" ./?.lua;/usr/share/lua/5.1/?.lua;/usr/share/lua/5.1/?/init.lua;/usr/lib
我刚刚从 https://github.com/llvm/llvm-project.git 安装了 clang++ 和 libc++ .尝试运行时: clang main.cpp -stdlib=li
我一直在使用 Highstock 图表,我注意到当图表中有很多点时,无法使用工具提示查看最后一个点: 您可以看到工具提示显示了 5 月 9 日的点,而还有一个显示 5 月 10 日的点(正如您在范围选
This question already has answers here: error_log message is truncated when using print_r (5个答案) 1年前
我在编写 Selenium 测试来检查我的应用程序时遇到问题。我想测试的是,当用户输入正确的登录名/密码时,会显示正确的页面并且用户已登录。 主要问题是我的登录表单是作为 AngularJS 指令生成
我正在尝试在 Azure 服务上发布我的 ASP.NET Core 应用程序。这有效,但是当我尝试使用应用程序功能时,我收到消息 Your App Service app is up and runn
在我的 ionic 应用程序中,我有一个功能,用户应该在应用程序的导航栏中看到水平点线,单击它们,然后应该出现一个弹出菜单,其中包含两个菜单项(添加到收藏夹并添加评论)。下图说明了我的观点。 问题是这
我是一名优秀的程序员,十分优秀!