首页 \ 问答 \ MyBatis-Spring多数据源配置缓存问题(MyBatis-Spring multi-datasource configuration cache issues)

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
更新时间:2023-05-12 18:05

最满意答案

检查一下。

<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'
        )
    )
)

check this one out.

<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'
        )
    )
)

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)