我的问题存在一个无级分类树中,因为对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;
- }
-
-
- }
分享到:
相关推荐
HQL语句 HQL语句 HQL语句 HQL语句 HQL语句
- `select new list(p.name, p.address) from Person as p`:创建一个包含`name`和`address`的列表作为结果集。 - `select new ClassTest(p.name, p.address) from Person as p`:实例化`ClassTest`类并传递`name`和...
- 在执行任何HQL查询之前,首先需要通过`SessionFactory`获取一个`Session`实例。 ```java Session session = HibernateUtil.getSessionFactory().openSession(); ``` 2. **编写HQL语句** - 根据需求编写相应...
hibernate-HQL语句大全
此语句将查询`Cat`实体,并将结果集中的每个实例映射为一个名为`cat`的对象。 ##### 3. JOIN子句 JOIN子句用于处理实体之间的关联关系,如一对一、一对多等。HQL支持内连接、左外连接、右外连接和全连接,其语法...
- `select new list(p.name, p.address) from Person as p` 创建一个包含name和address的列表。 - `select new ClassTest(p.name, p.address) from Person as p` 创建`ClassTest`类的新实例,传入name和address。 ...
Hibernate框架中,在使用HQL语句时,需要传递参数,而在HQL语句中使用in关键字时,需要特别注意参数的传递方式。在本文中,我们将讨论如何在HQL语句中使用in关键字带参数的写法,以及解决相关问题的方法。 一、HQL...
这里的 `Person` 是一个实体类,`AS p` 表示给 `Person` 类指定了一个别名 `p`,在后续的查询语句中可以通过这个别名来引用该实体类。如果不使用别名,则可以直接使用实体类名称。 #### 2. Select 子句 `SELECT` ...
常见HQL语句的示例包括输出结果,以及语句的分析总结
在Java开发中,Hibernate是一个非常流行的ORM(对象关系映射)框架,它提供了一种将数据库操作转换为面向对象的方式。HQL(Hibernate Query Language)是Hibernate提供的面向对象的查询语言,它类似于SQL,但更加...
HQL语句的使用是Hibernate中最重要的部分之一,本文将详细介绍HQL语句的使用方法和示例。 简单属性查询 HQL语句可以用于查询实体类中的简单属性,例如: ```java List students = session.createQuery("select ...
HQL语句查询
汇集了hql语句中大部分常用的函数 ABS(n) 取绝对值数学函数 数学函数 JPAQL HQL ABS(column_name[数字类型对象属性])
另一种格式(第10-16行)展示了如何在一个匿名内部类中使用`HibernateCallback`接口执行删除操作,这种方式在处理更复杂的逻辑时更为灵活。 3. **HQL单表查询**: HQL可以轻松地执行针对单个表的查询。第19行的HQL...
### Spring框架中HQL语句的使用方法 在学习Spring框架与Hibernate集成的过程中,掌握HQL(Hibernate Query Language)的使用方法是十分重要的。本文档将详细介绍如何在Spring环境中运用HQL进行数据查询操作,包括...
在本文档中所涉及的示例基于一个名为`joblog`的数据库,其中包含三个表:`student`(学生表)、`course`(课程表)和`sc`(选课表)。 - **学生表(student)**: - 字段包括:`id`(主键)、`sno`(学号)、`...
HQL(Hibernate Query Language)是Hibernate框架中用于操作对象关系映射(ORM)的查询语言,它是SQL的面向对象版本,使得开发者可以更方便地在Java应用中进行数据库查询。本教程将深入讲解HQL的基础语句,包括ID...
HQL语句(结合实例).doc HQL语句(结合实例).doc HQL语句(结合实例).doc