`
mlzboy
  • 浏览: 704861 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

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

阅读更多
我的问题存在一个无级分类树中,因为对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. //该类的父结点对象
  19.      private DictionaryLib dictionaryLib; 
  20. //该类关联的字典对象  
  21.      private Dictionary dictionary;   
  22.      private String name;   
  23.      private String description;   
  24.      private Integer sequence;   
  25.      private Short depth;   
  26.      private Date checkinTime;   
  27.      private Date updateTime;   
  28.      private Short version;   
  29.      private String status;   
  30.      private Set attachmentsForExtendName = new HashSet(0);   
  31.      private Set attachmentsForAttachmentType = new HashSet(0);   
  32. //该类子结点集
  33.      private Set dictionaryLibs = new HashSet(0);   
  34.   
  35.   
  36.     // Constructors   
  37.   
  38.     /** default constructor */  
  39.     public AbstractDictionaryLib() {   
  40.     }   
  41.   
  42.     /** minimal constructor */  
  43.     public AbstractDictionaryLib(Dictionary dictionary, String name) {   
  44.         this.dictionary = dictionary;   
  45.         this.name = name;   
  46.     }   
  47.        
  48.     /** full constructor */  
  49.     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) {   
  50.         this.dictionaryLib = dictionaryLib;   
  51.         this.dictionary = dictionary;   
  52.         this.name = name;   
  53.         this.description = description;   
  54.         this.sequence = sequence;   
  55.         this.depth = depth;   
  56.         this.checkinTime = checkinTime;   
  57.         this.updateTime = updateTime;   
  58.         this.version = version;   
  59.         this.status = status;   
  60.         this.attachmentsForExtendName = attachmentsForExtendName;   
  61.         this.attachmentsForAttachmentType = attachmentsForAttachmentType;   
  62.         this.dictionaryLibs = dictionaryLibs;   
  63.     }   
  64.   
  65.       
  66.     // Property accessors   
  67.   
  68.     public Integer getPkDictionaryLibId() {   
  69.         return this.pkDictionaryLibId;   
  70.     }   
  71.        
  72.     public void setPkDictionaryLibId(Integer pkDictionaryLibId) {   
  73.         this.pkDictionaryLibId = pkDictionaryLibId;   
  74.     }   
  75.   
  76.     public DictionaryLib getDictionaryLib() {   
  77.         return this.dictionaryLib;   
  78.     }   
  79.        
  80.     public void setDictionaryLib(DictionaryLib dictionaryLib) {   
  81.         this.dictionaryLib = dictionaryLib;   
  82.     }   
  83.   
  84.     public Dictionary getDictionary() {   
  85.         return this.dictionary;   
  86.     }   
  87.        
  88.     public void setDictionary(Dictionary dictionary) {   
  89.         this.dictionary = dictionary;   
  90.     }   
  91.   
  92.     public String getName() {   
  93.         return this.name;   
  94.     }   
  95.        
  96.     public void setName(String name) {   
  97.         this.name = name;   
  98.     }   
  99.   
  100.     public String getDescription() {   
  101.         return this.description;   
  102.     }   
  103.        
  104.     public void setDescription(String description) {   
  105.         this.description = description;   
  106.     }   
  107.   
  108.     public Integer getSequence() {   
  109.         return this.sequence;   
  110.     }   
  111.        
  112.     public void setSequence(Integer sequence) {   
  113.         this.sequence = sequence;   
  114.     }   
  115.   
  116.     public Short getDepth() {   
  117.         return this.depth;   
  118.     }   
  119.        
  120.     public void setDepth(Short depth) {   
  121.         this.depth = depth;   
  122.     }   
  123.   
  124.     public Date getCheckinTime() {   
  125.         return this.checkinTime;   
  126.     }   
  127.        
  128.     public void setCheckinTime(Date checkinTime) {   
  129.         this.checkinTime = checkinTime;   
  130.     }   
  131.   
  132.     public Date getUpdateTime() {   
  133.         return this.updateTime;   
  134.     }   
  135.        
  136.     public void setUpdateTime(Date updateTime) {   
  137.         this.updateTime = updateTime;   
  138.     }   
  139.   
  140.     public Short getVersion() {   
  141.         return this.version;   
  142.     }   
  143.        
  144.     public void setVersion(Short version) {   
  145.         this.version = version;   
  146.     }   
  147.   
  148.     public String getStatus() {   
  149.         return this.status;   
  150.     }   
  151.        
  152.     public void setStatus(String status) {   
  153.         this.status = status;   
  154.     }   
  155.   
  156.     public Set getAttachmentsForExtendName() {   
  157.         return this.attachmentsForExtendName;   
  158.     }   
  159.        
  160.     public void setAttachmentsForExtendName(Set attachmentsForExtendName) {   
  161.         this.attachmentsForExtendName = attachmentsForExtendName;   
  162.     }   
  163.   
  164.     public Set getAttachmentsForAttachmentType() {   
  165.         return this.attachmentsForAttachmentType;   
  166.     }   
  167.        
  168.     public void setAttachmentsForAttachmentType(Set attachmentsForAttachmentType) {   
  169.         this.attachmentsForAttachmentType = attachmentsForAttachmentType;   
  170.     }   
  171.   
  172.     public Set getDictionaryLibs() {   
  173.         return this.dictionaryLibs;   
  174.     }   
  175.        
  176.     public void setDictionaryLibs(Set dictionaryLibs) {   
  177.         this.dictionaryLibs = dictionaryLibs;   
  178.     }   
  179.     
  180.   
  181. }  
分享到:
评论
1 楼 chenkan2000 2007-07-25  
请用Nested Set model

相关推荐

Global site tag (gtag.js) - Google Analytics