本人新手 大家帮帮忙!hibernate 从子类查父类问题

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了本人新手 大家帮帮忙!hibernate 从子类查父类问题相关的知识,希望对你有一定的参考价值。

有一个主题topic类和一个回帖post类,根据topicId关联,一对多关系。我直接查符合某种条件的回帖(多个),我希望能把每个回帖对应的topic也查出来。
public class Bbs_topic
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(updatable = false)
private int topicId;
@OneToMany(cascade = CascadeType.ALL,fetch= FetchType.LAZY)
@JoinColumn(name="topicId")
private Set<Bbs_post> postSet;

public class Bbs_post
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(updatable = false)
private int postId;
@ManyToOne(targetEntity=Bbs_topic.class,cascade = CascadeType.ALL,fetch= FetchType.LAZY)//注解多对一
@JoinColumn(name="topicId")
private Bbs_topic bbs_topic;
private String postTitle;

我该怎么写hql语句???积分我有些,不是问题。万分感谢。

不明白你想表达什么意思,当你查出回帖的时候,不是已经查出回帖topic了吗
private Bbs_topic bbs_topic;追问

@ManyToOne(targetEntity=Bbs_topic.class,cascade = CascadeType.ALL,fetch= FetchType.LAZY)//注解多对一
@JoinColumn(name="topicId")
private Bbs_topic bbs_topic;
因为是fetch= FetchType.LAZY 所以查询例如( from Bbs_post where1=1)回帖的时候 bbs_topic是没有值的。fetch= FetchType.EAGER时是有值的

追答

有值的,你要显示的调用一下比如循环 list 显式的 调用一下 Bbs_post .getBbs_topic().getTitle();然后在一对多的关系中在多的这一方,即private Bbs_topic bbs_topic 这个不需要延迟调用,他对系统影响微乎其微,默认的就是EAGER

追问

嗯,确实是这样的,EAGER不会影响性能,十分感谢。我再问一个问题,我在查主题时要每个主题的回复量(就是回帖总数),以及第一页的回帖,应该怎么解决? 显示的时候主题显示在上面,回帖在下面分页显示。

参考技术A 你根据主题查询 Bbs_post 表,得到一个list,遍历list时 用 Bbs_post .Bbs_topic.topicId 可以得到topic。也可以把你写的代码复制出来。追问

我没有主题信息,所以不能根据主题查。我只需要看到所有被屏蔽的回帖,不管是哪个主题的。如果思路是:寻找每个主题下有没有被屏蔽的回帖,那就可以了。但是感觉数据量太大。

追答

根据屏蔽的回帖进行分组查询,得到所有的主题ID。这个工作量应该不大。如果做页面显示的话可以再进行分页。

参考技术B 不知道啊。

新买的I9100.串号353327/05/1611234 帮忙查一下产地和生产日期 S/N R21C96KPEZA

价格:2000多
刚买的I9100 店家说是港行的.我回来查了一下是欧水..按米井12580米369井查到生产日期是12年10月1日.听说生产日期JS能修改的..问下大侠们用串号查一下对不对,是不是12年10月1日生产的~

参考技术A 手机拨打*#*#197328640#*#*#*(Service Mode 服务模式 界面)
【1】 Debug Screen 调试模式 主要用于调试,并提供各种调试数据、手机参数的监看
【2】 Version Info 版本信息
【3】 UMTS RF NV UMTS射频校准
【4】 GSM RF NV GSM射频校准
【5】 AUDIO 里面有 Voice Call Video Call Multi-Audio Table ....等
【6】 COMMON 里面有FTM Debug Info RF Scanning ....等

选择 2 2 4 就可以查生产日期
进拨号盘:
输入*#06# 记下IMEI号
继续进拨号盘:
输入*#272*IMEI# IMEI就是你刚才记下的15位IMEI号码。
可以看到Sales Code后面的白框里会有3个字母。这个就是销售国的代码。记下到下表中查对应的国家即可。

Algeria.(阿尔及利亚)
ALG = ALGERIA
ALR = ALGERIA

Argentina.(阿根廷)
ANC = ARGENTINA
ARO = ARGENTINA
CTI = ARGENTINA
UFN = ARGENTINA
PSN = ARGENTINA

Aruba.(阿鲁巴)
ARU = ARUBA

Australia.(澳大利亚)
OPP = AUSTRALIA
OPS = AUSTRALIA
VAU = AUSTRALIA
XSA = AUSTRALIA
TEL = AUSTRALIA
HUT = AUSTRALIA

Austria.(奥地利)
AOM = AUSTRIA
DRE = AUSTRIA
MAX = AUSTRIA
MOB = AUSTRIA
MOK = AUSTRIA
ONE = AUSTRIA
TRG = AUSTRIA
ATO = AUSTRIA

Baltick.(波罗的海)
SEB = BALTICK

Belarus.(白俄罗斯)
MTB = BELARUS
VEL = BELARUS

Belgium.(比利时)
BAE = BELGIUM
BSE = BELGIUM
PRO = BELGIUM
XEB = BELGIUM

Bosnia-Herzegovina.(波斯尼亚 - 黑塞哥维那)
BHO = BOSNIA-HERZEGOVINA
BHT = BOSNIA-HERZEGOVINA
TEB = BOSNIA-HERZEGOVINA

Brazil.(巴西)
BTA = BRAZIL
BTM = BRAZIL
TMR = BRAZIL
ZTA = BRAZIL
ZVV = BRAZIL
ZTO = BRAZIL
ZTM = BRAZIL

Bulgaria.(保加利亚)
CMF = BULGARIA
GBL = BULGARIA
MTE = BULGARIA
MTL = BULGARIA
OMX = BULGARIA
PLX = BULGARIA
VVT = BULGARIA

Cambodia.(柬埔寨)
RCG = CAMBODIA

Canada.(加拿大)
RGS = CANADA
BMC = CANADA
TLS = CANADA

Chile.(智利)
CHB = CHILE
CHE = CHILE
CHL = CHILE
CHT = CHILE

China.(中国)
CUH = CHINA
INT = CHINA
TEC = CHINA
TIY = CHINA
CMC = CHINA
CHN = CHINA
CHZ = CHINA
M00 = CHINA

Colombia.(哥伦比亚)
COB = COLOMBIA
COL = COLOMBIA
COM = COLOMBIA
CGU = COLOMBIA

Costa Rica.(哥斯达黎加)
ICE = COSTA RICA

Croatia.(克罗地亚)
CRO = CROATIA
TRA = CROATIA
TWO = CROATIA
VIP = CROATIA

Cyprus.(塞浦路斯)
CYV = CYPRUS

Czech.(捷克)
ETL = CZECH
KBN = CZECH
OSK = CZECH
VDC = CZECH
XCS = CZECH
XEZ = CZECH
TMZ = CZECH
O2C = CZECH

Denmark.(丹麦)
DTL = DENMARK

Dominican Rep.(多米尼加代表)
CDR = DOMINICAN REP.
TDR = DOMINICAN REP.

Dominica.(多米尼加)
CST = DOMINICA
DCN = DOMINICA
DOR = DOMINICA

Ecuador.(厄瓜多尔)
BBE = ECUADOR

Egypt.(埃及)
EGY = EGYPT

El Salvador.(萨尔瓦多)
DGC = EL SALVADOR
TBS = EL SALVADOR

Finland.(芬兰)
ELS = FINLAND
SAU = FINLAND

France.(法国)
OFR = FRANCE
AUC = FRANCE
BOG = FRANCE
COR = FRANCE
DIX = FRANCE
FTM = FRANCE
NRJ = FRANCE
ORC = FRANCE
ORF = FRANCE
SFR = FRANCE
UNI = FRANCE
VGF = FRANCE
XEF = FRANCE

Germany.(德国)
DBT = GERMANY
DTM = GERMANY
DUT = GERMANY
EPL = GERMANY
MAN = GERMANY
MBC = GERMANY
VD2 = GERMANY
VIA = GERMANY
XEG = GERMANY
KOR = GERMANY

Ghana.(加纳)
SPN = GHANA

Greece.(希腊)
AOC = GREECE
COS = GREECE
EUR = GREECE
GER = GREECE
TGR = GREECE
VGR = GREECE
CYO = GREECE

Guatemala.(危地马拉)
PCS = GUATEMALA

Hong Kong.(香港)
TGY = HONG KONG

Hungary.(匈牙利)
PAN = HUNGARY
VDH = HUNGARY
WST = HUNGARY
TMO = HUNGARY
XEH = HUNGARY
TMH = HUNGARY

India.(印度)
HFC = INDIA
HYA = INDIA
INA = INDIA
IND = INDIA
INU = INDIA
IMS = INDIA
REL = INDIA
TAT = INDIA
INS = INDIA

Indonesia.(印尼)
AXI = INDONESIA
SAR = INDONESIA
XSE = INDONESIA

Iran.(伊朗)
THR = IRAN

Ireland.(爱尔兰)
3IE = IRELAND
VDI = IRELAND

Israel.(以色列)
CEL = ISRAEL
PCL = ISRAEL
PTR = ISRAEL

Italy.(意大利)
GOM = ITALY
HUI = ITALY
ITV = ITALY
OMN = ITALY
TIM = ITALY
VOM = ITALY
WIN = ITALY
XET = ITALY
FWB = ITALY

Ivory Coast.(象牙海岸)
IRS = IVORY COAST
SIE = IVORY COAST

Jamaica.(牙买加)
JBS = JAMAICA
JCN = JAMAICA
JCW = JAMAICA

Japan.(日本)
DCM = JAPAN
SBM = JAPAN
VFK = JAPAN

Jordan.(约旦)
LEV = JORDAN

Kazakhstan.(哈萨克斯坦)
EST = KAZAKHSTAN
KCL = KAZAKHSTAN
KMB = KAZAKHSTAN
KZK = KAZAKHSTAN
SKZ = KAZAKHSTAN

Kenya.(肯尼亚)
KEL = KENYA
KEN = KENYA

Korea.(韩国)
SKT = KOREA

Libyan Arab Rep.(利比亚阿拉伯精华)
MMC = LIBYAN ARAB REP

Lithuania.(立陶宛)
TLT = LITHUANIA

Luxemburg.(卢森堡)
LUX = LUXEMBURG

Ma文明用语.(澳门)
VTN = MA文明用语

Macedonia.(马其顿)
TMC = MACEDONIA
MBM = MACEDONIA

Malaysia.(马其顿)
CCM = MALAYSIA
MXS = MALAYSIA
FMG = MALAYSIA
FME = MALAYSIA
XME = MALAYSIA

Maxico.(墨西哥)
SEM = MAXICO
TCE = MAXICO
TMM = MAXICO
UNE = MAXICO

Mongolia.(蒙古)
MPC = MONGOLIA

Morocco.(摩洛哥)
WAN = MOROCCO
FWD = MOROCCO
MAT = MOROCCO
MED = MOROCCO
SNI = MOROCCO
MWD = MOROCCO

Netherlands.(荷兰)
BEN = NETHERLANDS
MMO = NETHERLANDS
ONL = NETHERLANDS
QIC = NETHERLANDS
TFT = NETHERLANDS
TNL = NETHERLANDS
VDF = NETHERLANDS
VDP = NETHERLANDS
XEN = NETHERLANDS
KPN = NETHERLANDS

New Zealand.(新西兰)
VNZ = NEW ZEALAND

Nigeria.(尼日利亚)
ECT = NIGERIA
GCR = NIGERIA
MML = NIGERIA

Norway.(挪威)
TEN = NORWAY

Pakistan.(巴基斯坦)
WDC = PAKISTAN
PAK = PAKISTAN

Panama.(巴拿马)
BPC = PANAMA
PCW = PANAMA
PBS = PANAMA

Peru.(秘鲁)
PEB = PERU
PET = PERU
SAM = PERU

Philippines.(菲律宾)
FAM = PHILIPPINES
XTC = PHILIPPINES
GLB = PHILIPPINES
XTE = PHILIPPINES
SMA = PHILIPPINES

Poland.(波兰)
ERA = POLAND
IDE = POLAND
PLS = POLAND
PRT = POLAND
XEO = POLAND

Portugal.(葡萄牙)
OPT = PORTUGAL
TMN = PORTUGAL
TPH = PORTUGAL
XEP = PORTUGAL
TCL = PORTUGAL

Puerto Rico.(波多黎各)
CEN = PUERTO RICO
PCI = PUERTO RICO
TPR = PUERTO RICO

Romania.(罗马尼亚)
CNX = ROMANIA
HAT = ROMANIA
ORO = ROMANIA
COA = ROMANIA

Russia.(俄罗斯)
AZC = RUSSIA
BLN = RUSSIA
EMT= RUSSIA
ERS = RUSSIA
GEO = RUSSIA
MTV = RUSSIA
SER = RUSSIA
SNT = RUSSIA

Saudi Arabia.(沙特阿拉伯)
JED = SAUDI ARABIA

Serbia Montenegro.(塞黑)
MSR = SERBIA MONTENEG
PMN = SERBIA MONTENEG
SMO = SERBIA MONTENEG
TSR = SERBIA MONTENEG
TOP = SERBIA MONTENEG

Singapore.(新加坡)
BGD = SINGAPORE
XSO = SINGAPORE
XSP = SINGAPORE

Slovenia.(斯洛文尼亚)
MOT = SLOVENIA
SIM = SLOVENIA

Slovakia.(斯洛伐克)
GTL = SLOVAKIA
IRD = SLOVAKIA
TMS = SLOVAKIA
ORS = SLOVAKIA

South Africa.(南非)
XFA = SOUTH AFRICA
XFC = SOUTH AFRICA
XFM = SOUTH AFRICA
XFV = SOUTH ARFICA
XFE = SOUTH AFRICA

South West Asia.(西南亚)
SWA = SOUTH WEST ASIA

Spain.(西班牙)
AMN = SPAIN
EUS = SPAIN
FOP = SPAIN
XEC = SPAIN
ATL = SPAIN

Sweden.(瑞典)
BAU = SWEDEN
BCN = SWEDEN
BME = SWEDEN
BSG = SWEDEN
BTH = SWEDEN
COV = SWEDEN
HTS = SWEDEN
SEN = SWEDEN
TET = SWEDEN
TLA = SWEDEN
XEE = SWEDEN
VDS = SWEDEN
TNO = SWEDEN

Switzerland.(瑞士)
AUT = SWITZERLAND
ORG = SWITZERLAND
MOZ = SWITZERLAND
SUN = SWITZERLAND
SWC = SWITZERLAND

Taiwan.(台湾)
TWM = TAIWAN
BRI = TAIWAN
TCC = TAIWAN
TCI = TAIWAN
CWT = TAIWAN

Temporary.(临时)
TEM = TEMPORARY

Thailand.(泰国)
CAT = THAILAND
THE = THAILAND
THL = THAILAND
THO = THAILAND
THS = THAILAND

Tanzania.(坦桑尼亚)
SOL = Tanzania

Tunesia.(突尼斯)
ABS = TUNISIA
RNG = TUNISIA

Turkey.(土耳其)
BAS = TURKEY
KVK = TURKEY
TUR = TURKEY
TLP = TURKEY
TRC = TURKEY

Ukraine.(乌克兰)
KVR = UKRAINE
SEK = UKRAINE
UMC = UKRAINE

United Arab Emirat.(阿联酋)
MID = UNITED ARAB EMIRAT
ARB = UNITED ARAB EMIRAT
XSG = UNITED ARAB EMIRAT
AFR = UNITED ARAB EMIRAT
ITO = UNITED ARAB EMIRAT

United Kingdom.(英国)
BTC = UNITED KINGDOM
O2I = UNITED KINGDOM
O2U = UNITED KINGDOM
ORA = UNITED KINGDOM
TMU = UNITED KINGDOM
TSC = UNITED KINGDOM
VOD = UNITED KINGDOM
XEU = UNITED KINGDOM
VIR = UNITED KINGDOM
H3G = UNITED KINGDOM
CPW = UNITED KINGDOM

USA.(美国)
AWS = USA
DOB = USA
TMB = USA
CLW = USA

Uzbekistan.(乌兹别克斯坦)
UZB = UZBEKISTAN

Venezuela.(委内瑞拉)
VMT = VENEZUELA

Vietnam.(越南)
XXV = VIETNAM
PHU = VIETNAM
XEV = VIETNAM
DNA = VIETNAM
FPT = VIETNAM
SPT = VIETNAM
TLC = VIETNAM
VTC = VIETNAM
VTL = VIETNAM

以上是关于本人新手 大家帮帮忙!hibernate 从子类查父类问题的主要内容,如果未能解决你的问题,请参考以下文章

android 怎么用json解析接口(本人新手,请大手帮忙解决下)

新手-ios

Hibernate之API初识及增删改查实现

Hibernate批量处理海量数据的方法

VMware上安装CentOS系统(本人新手,欢迎大家多多指导和关照)

latex 编译问题,求助!!!新手,第一次编,不知道怎么回事就是运行不了,报错也看不懂,大家帮帮忙吧