- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有两个对象,程序和分类,具有一个程序与多个分类的关系。这是我的条件查询:
Criteria crit2 = sessionFactory.getCurrentSession()
.createCriteria(Program.class)
.add(Restrictions.eq("code", input.getCode()))
.createAlias("classifications", "cl")
.add(Restrictions.eq("cl.id", 3249023L));
List<Program> programs2 = crit2.list();
它生成的 SQL 有一个额外的左外连接,我无法理解其目的?
Hibernate:
select
this_.id as id16_2_,
this_.created as created16_2_,
this_.modified as modified16_2_,
this_.version as version16_2_,
this_.active as active16_2_,
this_.adminProgramId as adminPro6_16_2_,
this_.code as code16_2_,
this_.deletable as deletable16_2_,
this_.desciption as desciption16_2_,
this_.discontinued as discont10_16_2_,
this_.effectiveDate as effecti11_16_2_,
this_.expirationDate as expirat12_16_2_,
this_.name as name16_2_,
this_.programVersion as program14_16_2_,
cl1_.id as id1_0_,
cl1_.created as created1_0_,
cl1_.modified as modified1_0_,
cl1_.version as version1_0_,
cl1_.causeOfLoss as causeOfL5_1_0_,
cl1_.code as code1_0_,
cl1_.description as descript7_1_0_,
cl1_.lobCode as lobCode1_0_,
cl1_.lobName as lobName1_0_,
cl1_.premiumBaseCode as premium10_1_0_,
cl1_.premiumBaseDesc as premium11_1_0_,
cl1_.premiumBaseValue as premium12_1_0_,
cl1_.program_id as program13_1_0_,
program4_.id as id16_1_,
program4_.created as created16_1_,
program4_.modified as modified16_1_,
program4_.version as version16_1_,
program4_.active as active16_1_,
program4_.adminProgramId as adminPro6_16_1_,
program4_.code as code16_1_,
program4_.deletable as deletable16_1_,
program4_.desciption as desciption16_1_,
program4_.discontinued as discont10_16_1_,
program4_.effectiveDate as effecti11_16_1_,
program4_.expirationDate as expirat12_16_1_,
program4_.name as name16_1_,
program4_.programVersion as program14_16_1_
from
Program this_
inner join
Classification cl1_
on this_.id=cl1_.program_id
left outer join
Program program4_
on cl1_.program_id=program4_.id
where
this_.code=?
and cl1_.id=?
有谁知道为什么这个 block 在那里:
left outer join
Program program4_
on cl1_.program_id=program4_.id
我怎样才能摆脱它,因为额外的连接会影响性能。
我使用的是hibernate 3.6.8
这是程序类:
package com.sg.pds.domain.entity.ratedelivery;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlTransient;
import org.hibernate.annotations.Index;
@XmlAccessorType(XmlAccessType.FIELD)
@Entity
public class Program extends BaseEntity {
private String code;
private String desciption;
private String name;
@XmlElement(name="classification") @XmlElementWrapper(name = "classifications")
private Set<Classification> classifications = new HashSet<Classification>();
@XmlElement(name="debitCredit") @XmlElementWrapper(name = "debitCredits")
private Set<DebitCredit> debitCredits = new HashSet<DebitCredit>();
@XmlElement(name="minPremium") @XmlElementWrapper(name = "minPremiums")
private Set<DebitCredit> minPremiums = new HashSet<DebitCredit>();
@XmlElement(name="deductible") @XmlElementWrapper(name = "deductibles")
private Set<Deductible> deductibles = new HashSet<Deductible>();
@XmlElement(name="optionalCoverage") @XmlElementWrapper(name = "optionalCoverages")
private Set<OptionalCoverage> optionalCoverages = new HashSet<OptionalCoverage>();
@XmlTransient
private Date expirationDate;
@XmlTransient
private Date effectiveDate;
@XmlTransient
private String programVersion;
@XmlTransient
private Boolean discontinued;
@XmlTransient
private Boolean active;
@XmlTransient
private Boolean deletable;
@XmlElement(name="company") @XmlElementWrapper(name = "companies")
private Set<String> companies = new HashSet<String>();
@XmlTransient
private Set<Territory> territories = new HashSet<Territory>();
@XmlTransient
private String adminProgramId; // primary key from program table in admin db
@OneToMany(cascade = {CascadeType.ALL}, mappedBy="program", fetch=FetchType.LAZY)
public Set<DebitCredit> getMinPremiums() {
return minPremiums;
}
public void setMinPremiums(Set<DebitCredit> minPremiums) {
this.minPremiums = minPremiums;
}
@OneToMany(cascade = {CascadeType.ALL}, mappedBy="program", fetch=FetchType.LAZY)
@OrderBy("lobCode ASC")
public Set<OptionalCoverage> getOptionalCoverages() {
return optionalCoverages;
}
public void setOptionalCoverages(Set<OptionalCoverage> optionalCoverages) {
this.optionalCoverages = optionalCoverages;
}
@OneToMany(cascade = {CascadeType.ALL}, mappedBy="program", fetch=FetchType.LAZY)
@OrderBy("lobCode ASC")
public Set<Deductible> getDeductibles() {
return deductibles;
}
public void setDeductibles(Set<Deductible> deductibles) {
this.deductibles = deductibles;
}
@OneToMany(cascade = {CascadeType.ALL}, mappedBy="program", fetch=FetchType.LAZY)
@OrderBy("name ASC")
public Set<Territory> getTerritories() {
return territories;
}
public void setTerritories(Set<Territory> territories) {
this.territories = territories;
}
@OneToMany(cascade = {CascadeType.ALL}, mappedBy="program", fetch=FetchType.LAZY)
@OrderBy("name ASC")
public Set<DebitCredit> getDebitCredits() {
return debitCredits;
}
public void setDebitCredits(Set<DebitCredit> debitCredits) {
this.debitCredits = debitCredits;
}
@ElementCollection
@CollectionTable(name="Company", joinColumns=@JoinColumn(name="program_id"))
@Column(name="name", length=255)
public Set<String> getCompanies() {
return companies;
}
public void setCompanies(Set<String> companies) {
this.companies = companies;
}
@OneToMany(cascade = {CascadeType.ALL}, mappedBy="program", fetch=FetchType.LAZY)
@OrderBy("code ASC")
public Set<Classification> getClassifications() {
return classifications;
}
public void setClassifications(Set<Classification> classifications) {
this.classifications = classifications;
}
public String getAdminProgramId() {
return adminProgramId;
}
public void setAdminProgramId(String adminProgramId) {
this.adminProgramId = adminProgramId;
}
@Column(length=255)
public String getProgramVersion() {
return programVersion;
}
public void setProgramVersion(String programVersion) {
this.programVersion = programVersion;
}
public Boolean getDiscontinued() {
return discontinued;
}
public void setDiscontinued(Boolean discontinued) {
this.discontinued = discontinued;
}
public Boolean getActive() {
return active;
}
public void setActive(Boolean active) {
this.active = active;
}
public Boolean getDeletable() {
return deletable;
}
public void setDeletable(Boolean deletable) {
this.deletable = deletable;
}
@Column(nullable = false)
@Temporal(TemporalType.DATE)
@Index(name="Program_EffectiveDate_idx")
public Date getEffectiveDate() {
return effectiveDate;
}
public void setEffectiveDate(Date effectiveDate) {
this.effectiveDate = effectiveDate;
}
@Temporal(TemporalType.DATE)
public Date getExpirationDate() {
return expirationDate;
}
public void setExpirationDate(Date expirationDate) {
this.expirationDate = expirationDate;
}
@Column(nullable = false, length=255)
@Index(name="Program_Code_idx")
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
@Column(length=255)
public String getDesciption() {
return desciption;
}
public void setDesciption(String desciption) {
this.desciption = desciption;
}
@Column(length=255)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean equals(Object obj) {
if((obj != null) && (obj.getClass() == this.getClass())) {
Long objId = ((Program)obj).getId();
if( objId != null && objId.equals(this.getId()) ){
return true;
}
}
return false;
}
}
分类如下:
package com.sg.pds.domain.entity.ratedelivery;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.CollectionTable;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.JoinColumn;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;
import org.hibernate.annotations.Index;
@XmlAccessorType(XmlAccessType.FIELD)
@Entity
public class Classification extends BaseEntity{
//@XmlElement(name="code")
private String code;
private String description;
@XmlElement(name="liabilityLimit") @XmlElementWrapper(name = "liabilityLimits")
private Set<LiabilityLimit> liabilityLimits = new HashSet<LiabilityLimit>();
@XmlTransient
private Program program;
private String lobName;
private String lobCode;
private String premiumBaseValue;
private String premiumBaseDesc;
private String premiumBaseCode;
private String causeOfLoss;
@XmlElement(name="coverage") @XmlElementWrapper(name = "coverages")
private Set<String> coverages = new HashSet<String>();
//@XmlTransient
//private Set<Rate> rates = new HashSet<Rate>();
//@XmlTransient
//private Set<Criterion> criteria = new HashSet<Criterion>();
@XmlElement(name="territory") @XmlElementWrapper(name = "territories")
private Set<Territory> territories = new HashSet<Territory>();
@OneToMany(cascade = {CascadeType.ALL}, mappedBy="classification")
public Set<Territory> getTerritories() {
return territories;
}
public void setTerritories(Set<Territory> territories) {
this.territories = territories;
}
//@OneToMany(mappedBy="classification")
//public Set<Criterion> getCriteria() {
// return criteria;
//}
//public void setCriteria(Set<Criterion> criteria) {
// this.criteria = criteria;
//}
//@OneToMany(mappedBy="classification")
//public Set<Rate> getRates() {
// return rates;
//}
//public void setRates(Set<Rate> rates) {
// this.rates = rates;
//}
@Column(length=255)
public String getPremiumBaseValue() {
return premiumBaseValue;
}
public void setPremiumBaseValue(String premiumBaseValue) {
this.premiumBaseValue = premiumBaseValue;
}
@Column(length=255)
public String getPremiumBaseDesc() {
return premiumBaseDesc;
}
public void setPremiumBaseDesc(String premiumBaseDesc) {
this.premiumBaseDesc = premiumBaseDesc;
}
@Column(length=255)
public String getPremiumBaseCode() {
return premiumBaseCode;
}
public void setPremiumBaseCode(String premiumBaseCode) {
this.premiumBaseCode = premiumBaseCode;
}
@Column(length=255)
public String getCauseOfLoss() {
return causeOfLoss;
}
public void setCauseOfLoss(String causeOfLoss) {
this.causeOfLoss = causeOfLoss;
}
@ElementCollection
@CollectionTable(name="Coverage", joinColumns=@JoinColumn(name="classification_id"))
@Column(name="name", length=255)
public Set<String> getCoverages() {
return coverages;
}
public void setCoverages(Set<String> coverages) {
this.coverages = coverages;
}
@ManyToOne
public Program getProgram() {
return program;
}
public void setProgram(Program program) {
this.program = program;
}
@OneToMany(cascade = {CascadeType.ALL}, mappedBy="classification")
@OrderBy("type ASC")
public Set<LiabilityLimit> getLiabilityLimits() {
return liabilityLimits;
}
public void setLiabilityLimits(Set<LiabilityLimit> liabilityLimits) {
this.liabilityLimits = liabilityLimits;
}
@Column(length=255)
@Index(name="Classification_Code_idx")
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
@Column(length=255)
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getLobName() {
return lobName;
}
public void setLobName(String lobName) {
this.lobName = lobName;
}
public String getLobCode() {
return lobCode;
}
public void setLobCode(String lobCode) {
this.lobCode = lobCode;
}
public boolean equals(Object obj) {
if((obj != null) && (obj.getClass() == this.getClass())) {
Long objId = ((Classification)obj).getId();
if( objId != null && objId.equals(this.getId()) ){
return true;
}
}
return false;
}
}
这是我的 session 工厂配置:
<bean id="sessionFactoryTester" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSourceLoader" />
<property name="packagesToScan" value="com.sg.pds.domain.entity" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.jdbc.fetch_size">0</prop>
<!-- Enable Hibernate's automatic session context management -->
<prop key="current_session_context_class">jta</prop>
<!--
<prop key="hibernate.hbm2ddl.auto">validate</prop>
-->
</props>
</property>
</bean>
最佳答案
这是因为 JPA 默认为 ManyToOne 关联预先加载。将 fetch 设置为惰性应该会删除额外的连接。
关于具有额外左外连接的 hibernate 条件查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9084097/
这个问题已经有答案了: Declaring multiple object pointers on one line causes compiler error (5 个回答) 已关闭 6 年前。 l
我目前正在学习语言处理器,经常出现的一个话题是语法中元素的使用方向。从左到右或从右到左。 我理解这个概念,但似乎有很多方法可以编写这些规则,我不确定它们是否都相同。到目前为止我看到的是: 右/左递归,
我有一个很长的线性(分支不多)流程图,在 graphviz 中显示为要么太高而无法放在单个页面上,要么太宽(如果方向是从左到右) 是否有一种简单的方法可以让 graphviz 以从左到右,然后向下,然
我一直摸不着头脑,但运气不好。设计器有一个包含 3 栏的站点、两个侧边栏和一个主要内容区域。 专为桌面设计,左栏、主要内容、右栏。但是,在较小的设备上,我们希望首先堆叠主要内容。 所以通常情况下,你可
我想要从上到下和从左到右组织的 css block 。 为了更好地解释这是一张图片,其中包含我到目前为止所获得的内容以及我希望使用 CSS 实现的内容: 代码如下: HTML: 1 2 3 4 5
当我问this question时,答案之一(现已删除)建议Either类型对应Curry-Howard correspondence中的XOR而不是OR,因为它不能同时是Left和Right。 真相
我有一个程序,如果用户按住向左或向右箭头键, Angular 色会逐渐朝那个方向加速,并最终达到最大速度。松开按键后, Angular 色逐渐减速,直至完全停止。 我的右方向键没问题,但左方向键坏了。
今天很简单的一个。我有一个专栏,我们称之为标题,有一堆项目标题。我需要从“:”的左侧拉出所有内容并进行左/右修剪(稍后我将在连接中使用它,但我现在只需要一个包含新数据的列) .下面是当前列的示例: 这
我正在尝试将图表中的列与左侧对齐。默认情况下,它们位于中间。 我在 API 文档中找不到任何关于此的信息。 Here是一个 jsFiddle 测试。 最佳答案 在 highcharts api 中,您
左旋转进位和右旋转进位指令有哪些实际用途? 在我的汇编课上,我们无法想出一个有用的好例子。 最佳答案 如果您想将位从一个操作数移出并移入另一个操作数: SHL EAX, 1 ; mov
我有一个查询,它使用 eqjoin 从两个不同的表返回以下数据。我想将 left 和 right 结合起来,而不是执行 zip() (重写 name > 和 joined_at),我想将右侧对象的属性
我使用 firebase API。发送和检索消息。但是,我在尝试为发送者/检索者设置布局时遇到麻烦,以便消息将左/右对齐。目前我只有发送者/检索者都使用的一种布局,但不确定如何设置不同的布局。 pub
我的菜单基本上是一个水平项目滑动条。所有菜单项都有特定的默认 CSS 属性。我希望这些项目在到达主容器的中心时更改其大小和左/右边距,并在离开主容器(或位于主容器之外)时重置为默认值。请参阅我的原理图
我有一个引用表,在这个表中有 3 个字段(Id、User1、User2)。 User2 字段可以为空,但我们在不使用时使用 0。 当我执行下面的 Linq 查询时,User2 == 0 的记录不是结果
不知道如何解决这个问题。 我有两个表结果和受访者 我需要查明受访者表中是否有任何行具有completion =“Complete”,但它们的respondent_id(在结果表和受访者表中)不在结果表
我正在尝试访问三个表以获得类似这样的内容: +------+------+------+ | ITEM | PCS | CSS | +------+------+------+ | 1099 |
left 和 right join 有区别吗,下面的sql 语句结果一样,但是两者的性能是一样的吗? SELECT count(*) FROM writers RIGHT JOIN blogs O
当我使用 LEFT() 使用以下代码从数据库中获取值时 $select="SELECT LEFT(description,500) FROM tbl_news where id='$id'"; $qu
当我将鼠标悬停在水平导航菜单上的页面名称上时,相关子页面会 float 在下方。 目前这些显示居中,我如何对齐它们以便它们向左对齐(与导航菜单标题名称一致)。 你可以去看到这个 http://79.1
在下面的引导网格示例中,它使用 col-sm 和 col-sm-push/pull。col-sm-push 指定了左/右值(偏移量)。 我不太清楚它是如何工作的。 第二个 float 元素来到第一个
我是一名优秀的程序员,十分优秀!