- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有实体:
第一
@Entity
@Getter
@Setter
@NoArgsConstructor
public class Technic implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
private String gosNumber;
private String invNumber;
private String shassisNumber;
private String engineNumber;
@Column(length = 100)
private String yearOfMake;
@ManyToOne
private Farm farm;
@JsonManagedReference
@ManyToOne
private TechGroup techGroup;
@JsonManagedReference
@ManyToOne
private TechType techType;
@JsonManagedReference
@ManyToOne
private TechMark techMark;
@JsonIgnore
@CreationTimestamp
@Column(name = "creation_date", updatable = false)
private LocalDateTime createdDate;
@JsonIgnore
@Column(name = "updated_date")
@UpdateTimestamp
private LocalDateTime updatedDate;
@JsonIgnore
@Column(columnDefinition = "Bool default false")
private Boolean isDel;
@JsonManagedReference
@OneToMany(mappedBy = "technic")
private List<TechnicStatus> technicStatusList = new ArrayList<>();
public List<TechnicStatus> getTechnicStatusList() {
return technicStatusList;
}
public void setTechnicStatus(TechnicStatus technicStatus) {
this.technicStatusList = new ArrayList<>();
this.technicStatusList.add(technicStatus);
}
第二:
@Entity
@Getter
@Setter
@NoArgsConstructor
public class TechnicStatus implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "technic_status_id")
private Long id;
@JsonBackReference
@ManyToOne
private Technic technic;
@JsonManagedReference
@ManyToOne
private Status status;
private Boolean isGarantia;
private Boolean isLizing;
private LocalDate visitedDate;
private LocalDate notWorkDate;
private String description;
@JsonIgnore
private boolean isActive;
@JsonIgnore
@CreationTimestamp
@Column(name = "creation_date", updatable = false)
private LocalDateTime createdDate;
}
我想从我的数据库中获取结果,其中包含每个对象 Technic 中的列表,我有 List technicStatusList = new ArrayList<>(),其中我只想拥有一个值为 isActive=true 的 TechnicStatus。
为此,我使用相同的 JPQL 查询:
TypedQuery<Technic> query = em.createQuery("Select t from Technic t join TechnicStatus ts on t.id = ts.technic.id where t.isDel=false and ts.isActive=true and t.farm.id=:farmId order by t.techGroup.name, t.techType.name, t.techMark.name", Technic.class);
但获得包含 TechnicStatus 的结果,该结果返回具有 true 和 false 的 TechnicStatus(TechnicStatus.isActive=true、TechnicStatus.isActive=false)。
我想获得此 native 查询的结果:
SELECT
*
FROM
technic
JOIN
technic_status ON technic.id = technic_status.technic_id
WHERE
technic.is_del = FALSE
AND technic_status.is_active = TRUE
AND technic.farm_id = 1722
最佳答案
与技术关联的技术状态列表将始终是您的映射定义的完整列表。
基本上你有两个选择。如果您仅曾经对状态为 Active 的 TechnicalStatus 感兴趣,那么您可以在协会。
@JsonManagedReference
@OneToMany(mappedBy = "technic")
@Where("active = 1")
private List<TechnicStatus> technicStatusList = new ArrayList<>();
https://dzone.com/articles/hibernate-where-clause
否则,您所做的就是从查询方法返回 TechnicalStatus 列表,这不是您想要的,但却是您所拥有的。
关于java - JPQL - 带过滤器的 JOIN 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54921445/
我想写这样的查询:- Select u from bookmaster u order by Year(b.createDate),Month(b.createDate),day(b.createDa
例如:选择不同的新 JPQA.QueryResultObjectV1(space.name,spaceID) "+ "from Space space,Building building,Floor
例如:选择不同的新 JPQA.QueryResultObjectV1(space.name,spaceID) "+ "from Space space,Building building,Floor
我有两张 table 第一张表 - 事件第二张表 - 类别 @Entity public class Event { @Id @GeneratedValue(strategy = Generation
我在我的 DAO 中使用 entityManager。 要创建表格,我使用: String CREATE_TABLE = "CREATE TABLE if not exists cats (name
在 JPQL 中,我可以通过以下方式检索实体: query = entityManager.createQuery("select c from Category c"); List categori
我需要执行以下选择: select c.address from Customer c where lower(trim(c.name)) = :name 但是我得到以下异常: javax.persi
我无法使此查询正常工作: Query query = eManager.createQuery("select c FROM News c WHERE c.NEWSID = :id",News.cla
我在我的 msql 表列中有 Long 类型,该列表示位标记。 我需要选择为其设置了所有几个标志的对象: columnValue & flags = columnValue 我尝试: javax.pe
请查看这篇文章的末尾(找到了另一种但也不起作用的方法)。第二种方式应该是更好的方式,如果有一天它起作用的话;) 我有一个由两个多对多关系组成的实体:MainEntity 有很多 A,MainEntit
首先声明我不是数据库专家。这些东西把我搞糊涂了,但不幸的是我在工作中被迫这样做,所以我有点卡住了:-) 我试图通过在 JPQL 中工作来获得一个复杂的订单,但我一点运气都没有。 我当前的查询如下所示:
我需要将此自联接转换为 JPQL: SELECT s1.* FROM site AS s1 JOIN (SELECT site_type, MAX(last_update_date) AS LastU
如果我有一个扩展 Fruit 的类 Apple,我如何编写一个 JPQL 查询来返回所有严格意义上是 Fruits 而不是 Apples 的对象? 最佳答案 这在 JPA 2.0 中是可能的,使用 T
我正在尝试获取 Order[] 数组,其中包括未收到相关文档的所有订单。 我尝试了这个查询,它返回了正确的行数。 @Query("Select o FROM Order o INNER JOIN o
我正在尝试根据用户可以选择的可能日期列表对日期进行搜索。使用日历,我要求用户输入一个日期,然后我想获取在“data_possibile”列表中具有该日期的所有可能数据包。 这是我正在使用的查询: @N
我想构建一个 JPQL 查询来将该结构的数据映射到这个 DTO: @AllArgsConstructor class UserDTO { long userId; long countOfCo
我必须对表执行批量更新。 做一个快速的例子: UPDATE Book b SET b.amount = b.amount + 1 WHERE b IN ( :books ) 问题是 b.amount
我有以下 JPA实体: @Entity class UserClient{ @Id @GeneratedValue(strategy = GenerationType.AUTO)
我有一个实体(例如 Setting),其中包含集合(例如 Settings.languages)和另一个对象(Language 的实例)。 有没有办法选择其集合实体中包含所需属性值的所有实体?例如获取
我正在使用 spring data jpa:过滤父对象的子对象的最佳方法是什么?在我下面的例子中我想要具有事件子对象的父对象,也只想要事件子对象作为父对象的列表 @Query(select dis
我是一名优秀的程序员,十分优秀!