- 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/
我只是没有明白这一点。下面的代码是怎么回事,哪里出错了?我必须上课:资源和预订。一个资源可以有多个预留,并且关系是双向的。对我来说,一切似乎都找到了,我已经查看了一堆资源和文档 - 是的,还有很多示例
我正在寻找有关大型遗留模式映射的一些建议。 情况是这样的。假设我们有一个名为 BusinessTransaction 的类。此类有几个引用用户 ID 的字段: @Entity public class
我正在寻找有关大型遗留模式映射的一些建议。 情况是这样的。假设我们有一个名为 BusinessTransaction 的类。此类有几个引用用户 ID 的字段: @Entity public class
我上课了: @Entity @Table(name="users") public class User{ private Integer id; private String name; priva
我有一个实体类 付款 其中有实体类 付款方式 与 多对一 关系。 现在因为我的 PaymentMethod 是主表。 所以我想在不影响主表 PaymentMethod 的情况下保存付款。 但是每次我保
关系的 @OneToMany 端填充良好,但 @ManyToOne 端每次都会覆盖(仅最后一项保留) @Entity @Table(name="order") public c
下面的联接保留了与每个客户端相关的 TaxJurisdictions,但它不包括插入中联接 (CLIENT_CODE) 中使用的列,导致我的数据库表 TBL_TAX_JURISDICTION.CLIE
我得到了城市和天气。天气应该指向数据库中的城市对象。一个城市可以有多个天气条目。我的问题是,每次我向数据库添加天气时,它都会创建一个具有相同名称但具有其他 ID 的新城市。 天气实体; @Entity
所以我的数据库中有一份文档有修订。文档表包含文档通用的元数据,修订版包含内容。目前我可以获得正确修订的文档。 我想做的是通过映射的所有修订获取文档列表。 这是我的两个实体: @Entity publi
大家好。 我有一个问题让我睡不着)例如,如果我有一个名为 Product 的实体(类)。我应该将这个产品与一堆图像链接起来。在数据库(在我的例子中是MySQL)中,我会创建一个产品表和图像表。图像表将
我使用 Spring Roo 对 MySQL 数据库进行逆向工程,这是一个我只有读取权限的数据库。 其中一个名为 Transaction 的实体有一个名为 originalTransaction 的字
我可以建立如下关系吗: @Entity Table1{ @ManyToOne @JoinColumn(name = "Column1", referen
我有以下单向 ManyToOne 关系: @Entity @Table(name = "Child") public class Child { @Id private Integer
我的关系非常简单,我的模型如下所示: public class Project { [PrimaryKey, AutoIncrement] public int ID { get; s
我有以下数据库结构: CREATE TABLE `author` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(255
目录 jpa实体@ManyToOne @OneToMany无限递归 问题描述 解决办法 @OneToMany和@ManyTo
我在保存具有 ManyToOne 双向关系的实体时遇到问题,这里是: 警告:HHH000437:正在尝试保存一个或多个与未保存的 transient 实体具有不可空关联的实体。在保存这些依赖实体之前,
我有 2 个实体 - 具有映射 @ManyToOne 的用户和角色。我想更改用户角色,但角色也想更新。 用户实体: @ManyToOne @JoinColumn(name = "role_id", i
我有 4 个类如下... @MappedSuperclass @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) public abstrac
想象一下下面的类 @Embeddable class A { @ManyToOne public B classB; ... public State someEnum
我是一名优秀的程序员,十分优秀!