을 선택하지만, 문제가 발생하여, 계몽하십시오최대 절전 모드가 나는 현재 JPA 개발 프로젝트를 사용하고 새로운 객체 생성자
예 :
@Query("
SELECT
new CustomerMaintain(c.content, u, c.createTime, c.updateTime)
FROM
CustomerMaintain c
JOIN
c.user u
WHERE
c.delFlag = FALSE AND c.customer.id = :customerId
")
CustomerMaintain.class
DTO : 나는 있다고 생각
@Entity
@Table(name = "t_customer_maintain")
@DynamicUpdate
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler", "delFlag"})
public class CustomerMaintain {
public CustomerMaintain() {
}
public CustomerMaintain(String content, User user, Date createTime, Date updateTime) {
this.content = content;
this.user = user;
this.createTime = createTime;
this.updateTime = updateTime;
}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(columnDefinition = "VARCHAR(512) DEFAULT ''")
private String content;
@ManyToOne(optional=false)
private User user;
@ManyToOne(optional=false)
private Customer customer;
@Column(columnDefinition = "TINYINT(1) DEFAULT FALSE ",insertable = false,updatable = false)
private Boolean delFlag;
@Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP",insertable = false,updatable = false)
private Date createTime;
@Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",insertable = false,updatable = false)
private Date updateTime;
// omission getter setter method
}
하나의 SQL 쿼리 만 :
SELECT
c.content,
u.id,
u.name,
u.head,
c.createTime,
c.updateTime
FROM
t_customerMaintain c
INNER JOIN
t_user u ...
,363,210
그러나 쿼리 결과를 최대 절전 모드는 이것이다 :
select
customerma0_.content as col_0_0_,
user1_.id as col_1_0_, /* only user.id fields */
customerma0_.createTime as col_2_0_,
customerma0_.updateTime as col_3_0_
from
t_customer_maintain customerma0_
inner join
t_user user1_
...
select
user0_.id as id1_4_0_,
user0_.head as head4_4_0_,
user0_.name as name5_4_0_
from
t_user user0_
where
user0_.id=? /* user1_.id as col_1_0_ */
질문 :
왜 첫 번째 SQL 쿼리에만 user.id
, 그리고 user.id
, user.name
, user.head
?
마지막 SQL 쿼리는 불필요합니다.
나는 다음과 같이 작성하려고 :
SELECT
new CustomerMaintain(c.content, new User(u.id, u.name, u.head), c.createTime, c.updateTime)
그러나 이렇게하면 비정상적으로 뭔가가 발생합니다 : new User(u.id, u.name, u.head)
이 제발 도와주세요,이 문제는 오랫동안 나를 괴롭 히고있다.
코드를 여러 줄로 포맷하여 도움을 줄 수있는 기회를 제공하십시오. 이것은 읽을 수 없습니다. 영어도 마찬가지입니다. – Alan
'CustomerMaintain' 클래스를 제공하십시오. – amir110
@Alan 죄송합니다, 서식을 완료했습니다. – guan