- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
阅读所有文档,在 @ManyToOne 上使用 @Fetch(FetchMode.JOIN) 默认情况下我相信会生成左外连接,但对我来说它总是生成内连接。这些是我的 bean :
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
/**
* PensionMember entity. @author MyEclipse Persistence Tools
*/
@Entity
@Table(name = "Z_PENSION_MEMBERS", schema = "DANAOS")
public class PensionMember implements java.io.Serializable {
private static final long serialVersionUID = -4541446336298304689L;
// Fields
private Long id;
private Long personsCode;
private String employeeCode;
private String personType;
private CrewOfficeEmployee employee;
private PersonTO person;
// Property accessors
@Id
@Column(name = "ID", unique = true, nullable = false, precision = 0)
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
@Column(name = "EMPLOYEE_CODE", length = 12)
public String getEmployeeCode() {
return this.employeeCode;
}
public void setEmployeeCode(String employeeCode) {
this.employeeCode = employeeCode;
}
@ManyToOne( cascade = CascadeType.REFRESH, optional=true )
@JoinColumn( name = "EMPLOYEE_CODE", insertable = false, updatable = false )
@Fetch(FetchMode.JOIN)
public CrewOfficeEmployee getEmployee(){
return employee;
}
public void setEmployee( CrewOfficeEmployee employee ){
this.employee = employee;
}
@Column(name = "PERSONS_CODE", precision = 126, scale = 0, insertable = false, updatable = false)
public Long getPersonsCode() {
return this.personsCode;
}
public void setPersonsCode(Long personsCode) {
this.personsCode = personsCode;
}
@ManyToOne( cascade = CascadeType.REFRESH, optional=true )
@JoinColumn( name = "PERSONS_CODE" )
@Fetch(FetchMode.JOIN)
public PersonTO getPerson() {
return person;
}
public void setPerson(PersonTO person) {
this.person = person;
}
@Column(name = "PERSON_TYPE", nullable = false, length = 1)
public String getPersonType() {
return this.personType;
}
public void setPersonType(String personType) {
this.personType = personType;
}
}
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
/**
* CrewOfficeEmployee entity. @author MyEclipse Persistence Tools
*/
@Entity
@Table(name = "Z_CREW_OFFICE_EMPLOYEES", schema = "DANAOS")
public class CrewOfficeEmployee implements java.io.Serializable {
private static final long serialVersionUID = -5900130959401376537L;
// Fields
private String id;
private Integer crewOfficeJobTitleId;
private String name;
private String surname;
private Date dateOfBirth;
private Date effectiveJoiningDate;
private Date joiningDate;
private Date leavingDate;
// Property accessors
@Id
@Column(name = "ID", unique = true, nullable = false, length = 12)
public String getId() {
return this.id;
}
public void setId(String id) {
this.id = id;
}
@Column(name = "JOB_TITLE_ID", nullable = false)
public Integer getCrewOfficeJobTitleId() {
return crewOfficeJobTitleId;
}
public void setCrewOfficeJobTitleId(Integer crewOfficeJobTitleId) {
this.crewOfficeJobTitleId = crewOfficeJobTitleId;
}
@Column(name = "NAME", nullable = false, length = 30)
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
@Column(name = "SURNAME", nullable = false, length = 30)
public String getSurname() {
return this.surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
@Column(name = "DATE_OF_BIRTH", nullable = false, length = 7)
public Date getDateOfBirth() {
return this.dateOfBirth;
}
public void setDateOfBirth(Date dateOfBirth) {
this.dateOfBirth = dateOfBirth;
}
@Column(name = "EFFECTIVE_JOINING_DATE", nullable = false, length = 7)
public Date getEffectiveJoiningDate() {
return this.effectiveJoiningDate;
}
public void setEffectiveJoiningDate(Date effectiveJoiningDate) {
this.effectiveJoiningDate = effectiveJoiningDate;
}
@Column(name = "JOINING_DATE", nullable = false, length = 7)
public Date getJoiningDate() {
return this.joiningDate;
}
public void setJoiningDate(Date joiningDate) {
this.joiningDate = joiningDate;
}
@Column(name = "LEAVING_DATE", length = 7)
public Date getLeavingDate() {
return this.leavingDate;
}
public void setLeavingDate(Date leavingDate) {
this.leavingDate = leavingDate;
}
}
这是我的查询:
Criteria crit = getSession().createCriteria(PensionMember.class);
crit.createAlias("employee", "employee");
crit.createAlias("person", "person");
crit.add(
Restrictions.or(
Restrictions.and(
Restrictions.eq( PERSON_TYPE, "V" ),
Restrictions.like( "person.personsSurname", surname, MatchMode.START ).ignoreCase()
),
Restrictions.and(
Restrictions.eq( PERSON_TYPE, "O" ),
Restrictions.like( "employee.surname", surname, MatchMode.START ).ignoreCase()
)
)
);
...这是生成的 SQL:
select * from ( select this_.ID as ID23020_6_, this_.EMPLOYEE_CODE as EMPLOYEE3_23020_6_, this_.PERSONS_CODE as PERSONS7_23020_6_,
this_.PERSON_TYPE as PERSON6_23020_6_, employee1_.ID as ID23010_0_, employee1_.JOB_TITLE_ID as JOB2_23010_0_,
employee1_.DATE_OF_BIRTH as DATE3_23010_0_, employee1_.EFFECTIVE_JOINING_DATE as EFFECTIVE4_23010_0_,
employee1_.JOINING_DATE as JOINING5_23010_0_, employee1_.LEAVING_DATE as LEAVING6_23010_0_,
employee1_.NAME as NAME23010_0_, employee1_.SURNAME as SURNAME23010_0_, person2_.STATUS_CODE as STATUS2_22758_1_, etc
from DANAOS.Z_PENSION_MEMBERS this_
inner join DANAOS.Z_CREW_OFFICE_EMPLOYEES employee1_ on this_.EMPLOYEE_CODE=employee1_.ID
inner join PERSONS person2_ on this_.PERSONS_CODE=person2_.PERSONS_CODE
where ((this_.PERSON_TYPE=? and lower(person2_.PERSONS_SURNAME) like ?) or
(this_.PERSON_TYPE=? and lower(employee1_.SURNAME) like ?)) ) where rownum <= ?
怎么会这样?!有人可以告诉我我做错了什么吗?
谢谢,尼尔
我正在使用 Hibernate 3.6.10 顺便说一句
最佳答案
意识到问题出在标准查询之后,解决方案是更改 createAlias() 方法:
Criteria crit = getSession().createCriteria(PensionMember.class);
crit.createAlias("employee", "employee", CriteriaSpecification.LEFT_JOIN);
crit.createAlias("person", "person", CriteriaSpecification.LEFT_JOIN);
关于java - @ManyToOne 与 JOIN FetchMode 生成内连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32944987/
我有两个表Employee和Department以下是它们的实体类 Department.java @Entity @Table(name = "DEPARTMENT") public class D
我有一个部门表和一个雇员表。 dept 表与 emp 表与 deptId 存在一对多关系。 当我尝试这段代码时: session.createCriteria(Dept.class).setFetch
我有一个包含子列表的父类。我想通过 id 以外的其他内容加载父级,例如按名称...我正在使用 criteria.setFetchMode("children",FetchMode.JOIN);和 cr
我正在尝试优化涉及多个库中的所有书籍和视频的复杂操作(这不是实际的域,出于保密原因)。 代码最初使用Criteria加载所有Libraries,然后通过迭代延迟加载成员Books。我基本上添加了几个
在我们的项目中,我们使用 Hibernate,并且在日志中我们观察到当我们没有指定 FetchMode 时,它有时使用 Join 有时使用 Select 来处理关系(据我所知是 FetchMode
指定lazy = "true"有什么区别并使用 fetch = "select" or "join" ?哪个比另一个更受欢迎? 问候 贾延德拉 最佳答案 假设我们有这样的实体: @Entity @Ta
我有以下类(class): @Entity public class TestContentElementResponse { @Id @GeneratedValue(strat
有什么方法可以编写集成测试来测试 FetchMode.Eager 是否正常工作?当我检索 MySubObject 时,我想验证它不会进入数据库。 代码: public MyObject GetEage
我在 Hibernate 论坛上问了这个问题,但没有得到完整的回复,所以我想我应该在这里重新发布它。这是原始问题线程: http://forum.hibernate.org/viewtopic.php
在我的 Grails 项目中,我有以下类: class A { static hasMany = [cs:C] } class B { static hasMany = [cs:C]
在一些现有代码上,我有以下语句(经过相当长的查询构建练习): return $statement->fetchAll( DBAL\FetchMode::CUSTOM_OBJECT, P
我有 2 个实体。第一个是 public class TechnicalDataItem { @EmbeddedId private ItemLabelId id; ID 类是: pu
阅读所有文档,在 @ManyToOne 上使用 @Fetch(FetchMode.JOIN) 默认情况下我相信会生成左外连接,但对我来说它总是生成内连接。这些是我的 bean : import jav
我有具有传递关系的实体。因此,实体 A 通过 OneToMany 映射到实体 B,实体 B 通过 OneToMany 与实体 C 映射。实体 A 有一个属性 userID,它不是主键,我需要从数据库中
这有效并显示结果集: $mainFeatures = new Mainfeature; $mainFeatures->getConnection()->setFetchMode(PDO::FETCH_
我们如何在 JPA 中将 FetchMode 指定为 JOIN?我确实知道在 hibernate 状态下我们可以通过 @Fetch(FetchType.JOIN) 来完成。但是我们如何在 JPA 中实
我需要将我的 hibernate 映射的获取模式设置为在某些情况下是急切的,而在其他情况下是惰性的。我的默认值(通过 hbm 文件设置)为 lazy="true"。如何在代码中覆盖此设置? MyCla
我有一个具有 @ManyToOne 关系的实体,我想通过单个查询检索它,因此使用 @Fetch(FetchMode.JOIN)。有时 Hibernate 不遵守这一点并发出 N+1 个 SELECT。
我有两张 table ,“玩家”和“元素”。玩家有一个元素 list 。我想使用分页检索玩家及其所有项目。我想根据玩家进行分页,而不考虑有多少项目。 所以我做这样的事情: Criteria c = s
我有以下实体结构(给出了数据库): @Data @Entity public class Report { @EmbeddedId private ReportId id;
我是一名优秀的程序员,十分优秀!