请教一个在无限级分类树中的HQL语句

本文探讨了如何使用HQL正确查询一个无级分类树结构的数据,具体问题是在DictionaryLib表中查找所有顶级节点,这些节点具有特定的fk_dictionary_id。
我的问题存在一个无级分类树中,因为对HQL语句不熟悉,所以想请
实际的sql语句如下:
select * from DictionaryLib where fk_dictionary_lib_parent_id is null and fk_dictionary_id=1
我尝试在createsqlquery中写如下代码,但是出错
java 代码
  1. String sql="select {d.*} from DictionaryLib d where {d.fk_dictionary_lib_parent_id} is null and {d.fk_dictionary_id}="+String.valueOf(dictionaryId);
肯请指点
下面我解释一下我的表结构,相关的有两张,
一张是DictionaryLib(即字典库表),该表构成一棵无级分类的树
pk_dictionary_lib_id是主键
fk_dictionary_lib_parent_id是该类的父类的id,若为顶类则为null
fk_dictionary_id是表dictionary字典表的外键,通过这个外键可以知道,每个类属于哪个字典
java 代码
  1. package com.lexus.bean;   
  2.   
  3. import java.util.Date;   
  4. import java.util.HashSet;   
  5. import java.util.Set;   
  6.   
  7.   
  8. /**  
  9.  * AbstractDictionaryLib generated by MyEclipse - Hibernate Tools  
  10.  */  
  11.   
  12. public abstract class AbstractDictionaryLib  implements java.io.Serializable {   
  13.   
  14.   
  15.     // Fields       
  16.   
  17.      private Integer pkDictionaryLibId;   
  18. //该类的父结点对象
     private DictionaryLib dictionaryLib;  //该类关联的字典对象        private Dictionary dictionary;         private String name;         private String description;         private Integer sequence;         private Short depth;         private Date checkinTime;         private Date updateTime;         private Short version;         private String status;         private Set attachmentsForExtendName = new HashSet(0);         private Set attachmentsForAttachmentType = new HashSet(0);    //该类子结点集      private Set dictionaryLibs = new HashSet(0);              // Constructors           /** default constructor */       public AbstractDictionaryLib() {        }           /** minimal constructor */       public AbstractDictionaryLib(Dictionary dictionary, String name) {            this.dictionary = dictionary;            this.name = name;        }                /** full constructor */       public AbstractDictionaryLib(DictionaryLib dictionaryLib, Dictionary dictionary, String name, String description, Integer sequence, Short depth, Date checkinTime, Date updateTime, Short version, String status, Set attachmentsForExtendName, Set attachmentsForAttachmentType, Set dictionaryLibs) {            this.dictionaryLib = dictionaryLib;            this.dictionary = dictionary;            this.name = name;            this.description = description;            this.sequence = sequence;            this.depth = depth;            this.checkinTime = checkinTime;            this.updateTime = updateTime;            this.version = version;            this.status = status;            this.attachmentsForExtendName = attachmentsForExtendName;            this.attachmentsForAttachmentType = attachmentsForAttachmentType;            this.dictionaryLibs = dictionaryLibs;        }                  // Property accessors           public Integer getPkDictionaryLibId() {            return this.pkDictionaryLibId;        }                public void setPkDictionaryLibId(Integer pkDictionaryLibId) {            this.pkDictionaryLibId = pkDictionaryLibId;        }           public DictionaryLib getDictionaryLib() {            return this.dictionaryLib;        }                public void setDictionaryLib(DictionaryLib dictionaryLib) {            this.dictionaryLib = dictionaryLib;        }           public Dictionary getDictionary() {            return this.dictionary;        }                public void setDictionary(Dictionary dictionary) {            this.dictionary = dictionary;        }           public String getName() {            return this.name;        }                public void setName(String name) {            this.name = name;        }           public String getDescription() {            return this.description;        }                public void setDescription(String description) {            this.description = description;        }           public Integer getSequence() {            return this.sequence;        }                public void setSequence(Integer sequence) {            this.sequence = sequence;        }           public Short getDepth() {            return this.depth;        }                public void setDepth(Short depth) {            this.depth = depth;        }           public Date getCheckinTime() {            return this.checkinTime;        }                public void setCheckinTime(Date checkinTime) {            this.checkinTime = checkinTime;        }           public Date getUpdateTime() {            return this.updateTime;        }                public void setUpdateTime(Date updateTime) {            this.updateTime = updateTime;        }           public Short getVersion() {            return this.version;        }                public void setVersion(Short version) {            this.version = version;        }           public String getStatus() {            return this.status;        }                public void setStatus(String status) {            this.status = status;        }           public Set getAttachmentsForExtendName() {            return this.attachmentsForExtendName;        }                public void setAttachmentsForExtendName(Set attachmentsForExtendName) {            this.attachmentsForExtendName = attachmentsForExtendName;        }           public Set getAttachmentsForAttachmentType() {            return this.attachmentsForAttachmentType;        }                public void setAttachmentsForAttachmentType(Set attachmentsForAttachmentType) {            this.attachmentsForAttachmentType = attachmentsForAttachmentType;        }           public Set getDictionaryLibs() {            return this.dictionaryLibs;        }                public void setDictionaryLibs(Set dictionaryLibs) {            this.dictionaryLibs = dictionaryLibs;        }            }  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值