hibernate查询问题

本文介绍了一个使用Struts框架实现的商品类别浏览功能的具体实现方式,包括如何通过Hibernate进行数据库交互来获取商品分类信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.hibernate.Hibernate;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.senyo.database.HibernateUtil;

/**
*
* @author senyo 2009-05-09
* 商品类别及商品的相关操作
*
*/
public class CommodityAction extends Action {

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
List cateList = null;

ActionForward forward=null;

try{
cateList = browseCategory();

if (cateList!=null) {
request.setAttribute("cateList", cateList);

forward=mapping.findForward("index");
}else{
forward=mapping.findForward("error");
}
}catch(Exception e){
e.printStackTrace();
}

return forward;
}
/** 浏览商品分类 */
public List browseCategory() throws Exception {
Session session = HibernateUtil.currentSession();
Transaction tx = null;
List list = null;
try{
Query query = session.createQuery("from Category as c order by c.id");
tx = session.beginTransaction();
list = query.list();
tx.commit();
if (!Hibernate.isInitialized(list)) {
Hibernate.initialize(list);
}
}catch(Exception ex){
if(tx!=null)tx.rollback();
System.out.println("在执行browseCategory方法时出错:\n");
ex.printStackTrace();
}finally{
HibernateUtil.closeSession();
}
return list;
}

}
为什么会是这样????一运行就出现这样的情况!!!!!
Hibernate: select category0_.cateid as cateid1_, category0_.categoryName as category2_1_, category0_.categoryInfo as category3_1_ from t_category category0_ order by category0_.cateid
Hibernate: select category0_.cateid as cateid1_, category0_.categoryName as category2_1_, category0_.categoryInfo as category3_1_ from t_category category0_ order by category0_.cateid
Hibernate: select category0_.cateid as cateid1_, category0_.categoryName as category2_1_, category0_.categoryInfo as category3_1_ from t_category category0_ order by category0_.cateid
Hibernate: select category0_.cateid as cateid1_, category0_.categoryName as category2_1_, category0_.categoryInfo as category3_1_ from t_category category0_ order by category0_.cateid
Hibernate: select category0_.cateid as cateid1_, category0_.categoryName as category2_1_, category0_.categoryInfo as category3_1_ from t_category category0_ order by category0_.cateid
Hibernate: select category0_.cateid as cateid1_, category0_.categoryName as category2_1_, category0_.categoryInfo as category3_1_ from t_category category0_ order by category0_.cateid
Hibernate: select category0_.cateid as cateid1_, category0_.categoryName as category2_1_, category0_.categoryInfo as category3_1_ from t_category category0_ order by category0_.cateid
Hibernate: select category0_.cateid as cateid1_, category0_.categoryName as category2_1_, category0_.categoryInfo as category3_1_ from t_category category0_ order by category0_.cateid
Hibernate: select category0_.cateid as cateid1_, category0_.categoryName as category2_1_, category0_.categoryInfo as category3_1_ from t_category category0_ order by category0_.cateid
Hibernate: select category0_.cateid as cateid1_, category0_.categoryName as category2_1_, category0_.categoryInfo as category3_1_ from t_category category0_ order by category0_.cateid
Hibernate: select category0_.cateid as cateid1_, category0_.categoryName as category2_1_, category0_.categoryInfo as category3_1_ from t_category category0_ order by category0_.cateid
Hibernate: select category0_.cateid as cateid1_, category0_.categoryName as category2_1_, category0_.categoryInfo as category3_1_ from t_category category0_ order by category0_.cateid
Hibernate: select category0_.cateid as cateid1_, category0_.categoryName as category2_1_, category0_.categoryInfo as category3_1_ from t_category category0_ order by category0_.cateid
Hibernate: select category0_.cateid as cateid1_, category0_.categoryName as category2_1_, category0_.categoryInfo as category3_1_ from t_category category0_ order by category0_.cateid
Hibernate: select category0_.cateid as cateid1_, category0_.categoryName as category2_1_, category0_.categoryInfo as category3_1_ from t_category category0_ order by category0_.cateid
Hibernate: select category0_.cateid as cateid1_, category0_.categoryName as category2_1_, category0_.categoryInfo as category3_1_ from t_category category0_ order by category0_.cateid
Hibernate: select category0_.cateid as cateid1_, category0_.categoryName as category2_1_, category0_.categoryInfo as category3_1_ from t_category category0_ order by category0_.cateid
Hibernate: select category0_.cateid as cateid1_, category0_.categoryName as category2_1_, category0_.categoryInfo as category3_1_ from t_category category0_ order by category0_.cateid
Hibernate: select category0_.cateid as cateid1_, category0_.categoryName as category2_1_, category0_.categoryInfo as category3_1_ from t_category category0_ order by category0_.cateid
Hibernate: select category0_.cateid as cateid1_, category0_.categoryName as category2_1_, category0_.categoryInfo as category3_1_ from t_category category0_ order by category0_.cateid
Hibernate: select category0_.cateid as cateid1_, category0_.categoryName as category2_1_, category0_.categoryInfo as category3_1_ from t_category category0_ order by category0_.cateid
Hibernate: select category0_.cateid as cateid1_, category0_.categoryName as category2_1_, category0_.categoryInfo as category3_1_ from t_category category0_ order by category0_.cateid

<think>好的,我现在要解决用户在IAR编译器中遇到的错误:“incomplete type is not allowed”。首先,我需要理解这个错误的含义和常见原因。根据我的知识库,这个错误常发生在代码中使用了未完全定义的类型,比如结构体或联合体声明了但未定义,或者前向声明了某个类型但没有提供完整的定义。 首先,我应该检查用户代码中是否有结构体或联合体的声明但没有定义的情况。比如,如果有一个结构体声明为`struct MyStruct;`,但没有后续的完整定义,那么在需要该结构体大小或成员的地方,编译器就会报这个错误。这时候,需要用户补全结构体的定义,包括成员变量。 其次,检查是否在头文件中只声明了类型而没有包含定义。例如,如果在头文件中使用前向声明,但在使用该类型的源文件中没有包含实际的定义头文件,这也会导致错误。此时,需要确保在使用类型的地方包含了正确的头文件,或者将前向声明替换为完整的定义。 另外,还要考虑typedef的问题。如果用户使用了typedef创建别名,但原始类型未完全定义,同样会引发错误。例如,`typedef struct MyStruct MyType;`之后,如果尝试使用MyType但MyStruct尚未定义,就会出错。需要确保在使用typedef之前,原始类型已经被完整定义。 此外,数组声明中的类型不完整也是一个常见原因。比如声明数组时,如果元素类型未完全定义,编译器无法确定数组的大小,导致错误。需要检查数组声明中的类型是否已经完整定义。 可能还有其他情况,比如在C和C++混合编程时,如果没有正确使用extern "C",或者在头文件中遗漏了必要的包含,也可能导致类型不完整。需要用户检查这些方面。 接下来,我需要将这些可能的原因整理成清晰的解决步骤,并给出具体的代码示例,帮助用户理解如何修改。同时,根据用户提供的引用内容,虽然引用[1]和引用[2]是关于其他错误的,但用户可能希望看到类似的结构,即分点说明解决方案,并引用相关资源。 最后,生成相关问题,帮助用户进一步了解可能相关的编译错误,比如类型未定义、前向声明问题等。这样用户可以有更全面的认识,预防其他类似错误的发生。</think>### IAR编译器错误'incomplete type is not allowed'解决方案 该错误表示代码中使用了**未完全定义的类型**,编译器无法确定其内存布局或成员信息。以下是具体原因及解决方法: #### 1. 结构体/联合体未定义完整 若声明了结构体但未定义成员,在实例化时会报错: ```c struct MyStruct; // 前向声明不完整 struct MyStruct var; // 错误:使用未完成类型 ``` **解决方案**:补全类型定义 ```c struct MyStruct { int id; char name[20]; }; ``` #### 2. 头文件包含缺失 当跨文件使用类型时,需确保定义可见: ```c // file.h struct Data; // 前向声明 // file.c struct Data { // 实际定义 int value; }; ``` **解决方案**:在使用该类型的文件中包含定义头文件 ```c #include "file.c" // 包含实际定义 ``` #### 3. typedef别名问题 使用typedef时原始类型必须完整: ```c typedef struct Node NodeT; // 前向声明 NodeT* ptr; // 允许指针声明 NodeT instance; // 错误:不完整类型 ``` **解决方案**:先完成类型定义再typedef ```c struct Node { int data; struct Node* next; }; typedef struct Node NodeT; ``` #### 4. 数组声明不完整 数组元素类型必须完全定义: ```c struct Element; struct Element arr[10]; // 错误:元素类型未定义 ``` **解决方案**: ```c struct Element { int type; float value; }; struct Element arr[10]; // 合法 ``` #### 调试建议 1. 在IAR工程中搜索错误行号定位问题代码 2. 使用Go to Definition功能追踪类型定义 3. 检查所有头文件包含链 4. 确认没有循环依赖的头文件 编译器需要知道类型的完整信息才能: - 计算sizeof大小 - 分配内存空间 - 访问成员变量 - 进行类型对齐 [^1]: 类似类型转换错误可参考浮点转整型的类型适配问题。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值