MyBatis-Spring多数据源配置缓存问题(MyBatis-Spring multi-datasource configuration cache issues)
使用mybatis-3.1.0,spring-3.1.1.RELEASE和mybatis-spring-1.1.0,我们在多数据源配置中面临一些讨厌的缓存问题。
出于安全原因,我们有单独的数据源指向相同的数据库和模式,每个数据源使用不同的凭据。 目标是使用仅具有选择权限的db用户进行选择,使用具有插入/更新/删除权限的另一用户执行dml操作,等等。
为此,我们配置了三个独立的SqlSessionFactoryBeans,每个数据源一个。 问题出现在这里:当使用“DML”会话执行插入操作时,不会刷新“SELECT”会话的本地缓存。 因此,例如,我们在用户列表中看不到新创建的用户。
所以我的问题是:我们是否有办法同时配置与所有三个数据源关联的单个SqlSessionFactoryBean?
更新:
经过一些调试后,看起来核心问题实际上与事务管理有关。 站点中的某些操作涉及多个操作,这些操作通过不同的数据源执行。 看起来我们没有正确配置事务管理器,并且这些操作中的一个或多个被排除在提交之外。 经过多次尝试,当连接耗尽时,数据库操作完全搞砸了。
那么,现在的问题是,如何配置单个事务管理器来处理所有涉及的数据源?
Using mybatis-3.1.0, spring-3.1.1.RELEASE, and mybatis-spring-1.1.0, we are facing some nasty cache issues in a multi-datasource configuration.
For security reasons, we have separate datasources pointing to the same database and schema, each datasource using different credentials. The goal is to use a db user having only select permissions for doing selects, another user with insert/update/delete permissions to do dml operations, and so on.
For doing so, we have configured three separate SqlSessionFactoryBeans, one for each datasource. And the problem comes here: when an insert operation is performed using the "DML" session, the local cache of "SELECT" sessions is not flushed. Therefore, for example, we do not see newly created users in the user list.
So my question is: do we have any way of configuring a single SqlSessionFactoryBean associated to all three datasources at the same time?
Update:
After some more debugging, it looks like the core issue is actually transaction management related. Some actions in the site involve several operations, and these operations are performed through different datasources. It looks like we are not correctly configuring the transaction manager, and one or more of those operations are left out of the commit. After several attempts, as the connections are exhausted, database operations get totally messed up.
So, the question now is, how to configure a single transaction manager to handle all involved datasources?
原文:https://stackoverflow.com/questions/24951101
最满意答案
检查一下。
<input type="text" name="firstname"> <input type="text" name="lastname"> <input type="text" name="email"> <input type="text" name="address"> <input type="text" name="tree[tree1][fruit]"> <input type="text" name="tree[tree1][height]"> <input type="text" name="tree[tree2][fruit]"> <input type="text" name="tree[tree2][height]"> <input type="text" name="tree[tree3][fruit]"> <input type="text" name="tree[tree3][height]">
它应该像$ _POST []数组(PHP格式容易可视化)最终如此
$_POST[] = array( 'firstname'=>'value', 'lastname'=>'value', 'email'=>'value', 'address'=>'value', 'tree' => array( 'tree1'=>array( 'fruit'=>'value', 'height'=>'value' ), 'tree2'=>array( 'fruit'=>'value', 'height'=>'value' ), 'tree3'=>array( 'fruit'=>'value', 'height'=>'value' ) ) )
<input type="text" name="firstname"> <input type="text" name="lastname"> <input type="text" name="email"> <input type="text" name="address"> <input type="text" name="tree[tree1][fruit]"> <input type="text" name="tree[tree1][height]"> <input type="text" name="tree[tree2][fruit]"> <input type="text" name="tree[tree2][height]"> <input type="text" name="tree[tree3][fruit]"> <input type="text" name="tree[tree3][height]">
it should end up like this in the $_POST[] array (PHP format for easy visualization)
$_POST[] = array( 'firstname'=>'value', 'lastname'=>'value', 'email'=>'value', 'address'=>'value', 'tree' => array( 'tree1'=>array( 'fruit'=>'value', 'height'=>'value' ), 'tree2'=>array( 'fruit'=>'value', 'height'=>'value' ), 'tree3'=>array( 'fruit'=>'value', 'height'=>'value' ) ) )
相关问答
更多-
检查一下。您可以在HTML5中执行此操作,但否则您必须使用JavaScript。 HTML5允许您将autofocus添加到表单元素中,例如: 这在支持HTML5的浏览器(或者是支持HTML5的特定部分的浏览器)中起作用,但是您知道,并不是每个人都可以使用它。 You can do it in HTML5, but otherwise, you must use JavaScript. HTML5 allows you t ...
HTML表单提交 - 将输入值添加到JavaScript数组(HTML Form Submission - add input vales to javascript array)[2021-10-20]
function createContact():void{ let firstName =document.getElementById("firstName");//HTML Element let surname = document.getElementById("surname"); let phoneNumber = document.getElementById("phoneNumbe ... 我要做的是将所有字段放在表单中,并用div分隔步骤。 在页面加载时,您隐藏所有步骤(第一个除外)。 单击按钮后,将显示下一步。 最后一步没有按钮,而是一个提交按钮,使其触发表单。 $(function() { $('form>div:not(:first)').hide(); /* hide all but first step */ $('form').on('click', 'button', function(e) { e.preventDefault(); v ...将JavaScript数组通过HTML表单传递给另一个js文件(Passing a javascript array through HTML form to another js file)[2023-07-27]
你有有效的JSON字符串,当你解析它时var questions = JSON.parse(req.body.questions); 你得到了对象Array - 我们到目前为止是好的(嵌套Array没有问题)。 第一个问题在你尝试解析var answers = JSON.parse(req.body.questions.answers);时开始var answers = JSON.parse(req.body.questions.answers); 。 req.body.questions在这一点上是一个S ...1)您无法保存该值的原因是因为您从click函数之外的输入字段中获取值。您应该在执行单击后尝试获取该值。 2)你可以通过给它一个id例如类别并获得它的值来获得selectbox值 var category = document.getElementById("category").value; 看下面的代码:我已经放置了代码,它在insert()函数中获取表单值。 我给了select box一个id作为类别,并使用相同的ID来检索值。 并使用innerHTML display div存储在display ...使用Web Html表单创建Javascript数组[关闭](Javascript Array Creation Using A Web Html Form [closed])[2022-01-05]
此代码用于填充表单中的所有无线电值: var theArray = [] $("#what > input[type='radio']").each(function(){ theArray.push($(this).val()) }) // theArray will be like this: red,blue,green,dog,parrot,horse 如果要将checked属性与数组一起传递,可以执行以下操作: theArray.push($(this).val() + "@" + this ...你不能像这样发送数组。 它将返回Array 。 你可以这样做