最近一周在做一些查询的优化,看着一两年前写的东西就在抱怨 为什么原先不这么这么写......
好吧,谁让你一开始就没定下所谓的业务呢......
其实优化工作很简单,去除无用的表连接,不过因为整个查询是由criteria构建,所以你的VO关系决定了你的criteria path是不是最优的。
原来的逻辑是A -> AB -> B -> C
由于B是一张KW级别的表,加上C有B字段
所以就改成 A-> AB -> C,
在AB中建个关联 到 C
如下:
class A{
.......
}
class B{
......
}
class AB{
private A a;
private B b;
private Set<C> c = new HashSet<C>(0);
@OneToMany(fetch = FetchType.LAZY)
@JoinColumn(name = "B_ID")
public Set<C> getC(){
return c;
}
}
class C{
private B b
}
不过很可惜,因为AB 中已经有个以B_ID 为外键关联到B了,而AB是复合主键,所以在写上述的mapping时候会报
foreign key must have same number of columns as the referenced primary key.
它把复合主键给你和B_id给mapping 上了,真够傻X的,难道就不能关联单个么。
好吧,改成
class AB{
private A a;
private B b;
private Set<C> c = new HashSet<C>(0);
@OneToMany(fetch = FetchType.LAZY)
@JoinColumn(name = "B_ID",referencedColumnName="B_ID")
public Set<C> getC(){
return c;
}
}
就OK了
分享到:
相关推荐
执行SQL报错:The used SELECT statements have a different number of columns 以上翻译:使用的SELECT语句具有不同数量的列 原因:我们在 SQL 语句中使用了 UNION 连接两张表时,查询字段数量不一致导致 # 效果...
(b) the name of the table, the names of the table's attributes, the data types of the table's attributes, the formats of the table's attributes, and the maximum number of rows that the table can have ...
mysql 提示SQL-ERROR summary different number of columns
Getting the number of columns in report view获得列表视图的列数(2KB)
最近需要对表头进行冻结,找到了bootstrap-table-fixed-columns组件(也是bootstrap-table作者写的)能实现冻结效果,但带来了其他问题,包括:排序失效、列宽错位、合并行无效等,于是引入该组件的同时,顺便解决了...
fastadmin 表格添加固定表头 bootstrap-table-fixed-columns所需插件
如有使用疑问,联系博主 bootstrap-table-fixed-columns.css固定列 冻结列
如有使用疑问,联系本人,如有使用疑问,
bootstrap-table-fixed-columnsbootstrap-table-fixed-columnsbootstrap-table-fixed-columns
fixed-columns表格固定列。
在原bootstrap-table-fixed-columns的基础上,解决了冻结列后,排序失效、列宽错位和合并行失效问题
HHT变换的matlab语句,仅供参考,如有问题请指出,谢谢。
Keeping your clustered key value small increases the number of index rows that can be placed on an index page and decreases the number of levels that must be traversed. This minimizes I/O. As we’ll ...
bootstrap-table样式固定列js插件,在网上看到下载资源比较少,免费提供给大家下载使用,方便开发进度。
error('The ''start'' matrix must have the same number of columns as X.'); end if isempty(reps) reps = size(CC,3); elseif reps ~= size(CC,3); error('The third dimension of the ''start'' array ...
Non-linear behavior of non-contact H-shaped beam-columns under axial force and biaxial bending,MARTINEZ RIVERO Alejandro,陈以一,The increasing importance and vitality of research on non-linear ...
矩阵 这是的Matrix类。 有几种创建矩阵的方法: # Creates a Matrix of Int32 with 3 rows and 2 columns. A Tuple of rows can also ...# must have the same number of elements. Matrix .columns([