我的问题存在一个无级分类树中,因为对HQL语句不熟悉,所以想请
实际的sql语句如下:
select * from DictionaryLib where fk_dictionary_lib_parent_id is null and fk_dictionary_id=1
我尝试在createsqlquery中写如下代码,但是出错
java 代码
- 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 代码
- package com.lexus.bean;
-
- import java.util.Date;
- import java.util.HashSet;
- import java.util.Set;
-
-
-
-
-
-
- public abstract class AbstractDictionaryLib implements java.io.Serializable {
-
-
-
-
- private Integer pkDictionaryLibId;
- //该类的父结点对象
- 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);
-
-
-
-
-
- public AbstractDictionaryLib() {
- }
-
-
- public AbstractDictionaryLib(Dictionary dictionary, String name) {
- this.dictionary = dictionary;
- this.name = name;
- }
-
-
- 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;
- }
-
-
-
-
- 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;
- }
-
-
- }