최대 절전 모드 쿼리 시스템을 도와주세요. 나는 그들은 연결되어있는 두 테이블최대 절전 모드 쿼리 시스템
CREATE TABLE public.news_category_dict
(
id SERIAL PRIMARY KEY NOT NULL,
name VARCHAR(64) NOT NULL
);
CREATE UNIQUE INDEX news_category_dict_name_uindex ON public.news_category_dict (name);
CREATE TABLE public.news
(
id SERIAL PRIMARY KEY NOT NULL,
category_id INT2,
name VARCHAR(64) NOT NULL,
created TIMESTAMP DEFAULT now() NOT NULL,
data TEXT NOT NULL
);
CREATE UNIQUE INDEX news_name_uindex ON public.news (name);
ALTER TABLE public.news
ADD CONSTRAINT news_news_category_dict_id_fk
FOREIGN KEY (category_id) REFERENCES news_category_dict (id) ON UPDATE CASCADE;
, 그래서 나는
SELECT d.name, n.name, n.data
FROM public.news AS n, public.news_category_dict AS d
WHERE n.category_id = d.id
내가 SQL에서 그것을 할 방법을 알고이 쿼리를 원하지만, HQL과 기준을 수행하는 방법을 이해하지 않습니다 API.
도와주세요 PLZ.
편집
확인. 여기 내 매핑은 다음과 같습니다
public class News implements Serializable {
private int id;
private String name;
private Date created;
private String data;
private NewsCategoryDict category;
}
public class NewsCategoryDict implements Serializable {
private static final long serialVersionUID = 1L;
private int id;
private String name;
private List<News> news = new ArrayList<>();
}
나는이 조각 사용하는 경우 : 내가 추적과보고
Criteria crit = sessionFactory.getCurrentSession().createCriteria(News.class);
return crit.list();
이 SQL 스크립트를
select
this_.id as id1_4_0_,
this_.category_id as category5_4_0_,
this_.created as created2_4_0_,
this_.data as data3_4_0_,
this_.name as name4_4_0_
from
news this_
을 그리고 나도 카테고리 이름 필드를보고 싶어요.
아하. 나는 undestand 시작합니다. Criteria API는 무엇입니까? – R1K0
확인. 따라서 링크가있는 클래스에 대한 데이터를 얻는 것만으로도 그 클래스와 연결된 모든 클래스에 대한 전체 정보를 얻을 수 있습니까? – R1K0
내 질문을 편집합니다. – R1K0