java 映射出错,找了一年了BUG了
出错内容:org.springframework.orm.hibernate3.HibernateSystemException: Unknown entity: com.thit.oa.bean.ProjProcess; nested exception is org.hibernate.MappingException: Unknown entity: com.thit.oa.bean.ProjProcess
网上找了很多,什么类名呀都有比对过。 最纠结的是这是新加的项目内容容管理业务,之前的都可以的。。 肯定是那里有小问题,请大家帮看看。
Action:
//增加项目
public String addMyProjProcess(){
UserInfo userInfo=(UserInfo)request.getSession().getAttribute("user");
try {
System.out.println(this.projProcess.getBusinessName()+" "+this.projProcess.getCustomName());
String createTime=new Date().toLocaleString();
// String a= createTime.substring(0, 8);
// System.out.println(a);
this.projProcess.setCreateTime(createTime);
this.projProcess.setUserInfo(userInfo);
//this.projProcess.setBusinessName(businessName);
} catch (Exception e) {
e.printStackTrace();
}
OperateLog operateLog=new OperateLog();
try {
operateLog.setObjectId(""+userInfo.getUserName());
operateLog.setOperateName("增加");
operateLog.setOperateTime(new Date().toLocaleString());
operateLog.setUserInfo(userInfo);
projProcessBizDao.insert(this.projProcess);
operateLog.setOperateDesc("增加项目成功");
} catch (Exception e) {
e.printStackTrace();
operateLog.setOperateDesc("增加项目失败");
}
finally{
try {
operateLogBizDao.insert(operateLog);
} catch (Exception e) {
e.printStackTrace();
}
}
return SUCCESS;
}
<!-- 配置映射文件 -->
<property name="mappingResources">
<list>
<value>com/thit/oa/bean/WorkTime.hbm.xml</value>
<value>com/thit/oa/bean/Message.hbm.xml</value>
<value>com/thit/oa/bean/BranchInfo.hbm.xml</value>
<value>com/thit/oa/bean/MyNote.hbm.xml</value>
<value>com/thit/oa/bean/MeetingInfo.hbm.xml</value>
<value>com/thit/oa/bean/RoleInfo.hbm.xml</value>
<value>com/thit/oa/bean/DepartInfo.hbm.xml</value>
<value>com/thit/oa/bean/RoleRight.hbm.xml</value>
<value>com/thit/oa/bean/RightInfo.hbm.xml</value>
<value>com/thit/oa/bean/ReadCommonMessage.hbm.xml</value>
<value>com/thit/oa/bean/LoginLog.hbm.xml</value>
<value>com/thit/oa/bean/Schedule.hbm.xml</value>
<value>com/thit/oa/bean/PreContract.hbm.xml</value>
<value>com/thit/oa/bean/ManualSign.hbm.xml</value>
<value>com/thit/oa/bean/MessageType.hbm.xml</value>
<value>com/thit/oa/bean/AccessoryFile.hbm.xml</value>
<value>com/thit/oa/bean/FileInfo.hbm.xml</value>
<value>com/thit/oa/bean/OperateLog.hbm.xml</value>
<value>com/thit/oa/bean/UserInfo.hbm.xml</value>
<value>com/thit/oa/bean/FileTypeInfo.hbm.xml</value>
<value>com/thit/oa/bean/MessageToUser.hbm.xml</value>
<value>com/thit/oa/bean/ProjProcess.hbm.xml</value>
</list>
</property>
XML ProjProcess.hbm.xml:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="com.thit.oa.bean.ProjProcess" table="ProjProcess" schema="dbo" catalog="MyOffice">
<id name="projProcessId" type="java.lang.Integer">
<column name="ProjProcessId" />
<generator class="native"></generator>
</id>
<!-- many-to-one name="projProcess" class="com.thit.oa.bean.ProjProcess" update="false" insert="false" fetch="select">
<column name="ProjProcessId" not-null="true" unique="true" />
</many-to-one-->
<many-to-one name="userInfo" class="com.thit.oa.bean.UserInfo" fetch="select">
<column name="CreateUser" />
</many-to-one>
<property name="customName" type="java.lang.String">
<column name="CustomName" length="50" />
</property>
<property name="model" type="java.lang.String">
<column name="Model" length="50" />
</property>
<property name="businessName" type="java.lang.String">
<column name="BusinessName" length="10" />
</property>
<property name="planCompleteDate" type="java.lang.String">
<column name="PlanCompleteDate" length="20" />
</property>
<property name="planUpdateDate" type="java.lang.String">
<column name="PlanUpdateDate" length="20" />
</property>
<property name="stateDesc" type="java.lang.String">
<column name="StateDesc" length="500" />
</property>
<property name="needsDesc" type="java.lang.String">
<column name="NeedsDesc" length="500" />
</property>
<property name="createTime" type="java.lang.String">
<column name="CreateTime" length="20" />
</property>
<property name="projProcessType" type="java.lang.String">
<column name="ProjProcessType" length="30" />
</property>
<set name="projProcesses" inverse="true">
<key>
<column name="ProjProcessId" not-null="true" unique="true" />
</key>
<one-to-many class="com.thit.oa.bean.ProjProcess" />
</set>
</class>
</hibernate-mapping>
JAVA BEAN (ProjProcess.java) :
package com.thit.oa.bean;
// default package
import com.thit.oa.bean.UserInfo;
import java.util.HashSet;
import java.util.Set;
/**
* ProjProcess generated by MyEclipse Persistence Tools
*/
public class ProjProcess implements java.io.Serializable {
// Fields
private Integer projProcessId;
// private ProjProcess projProcess;
private UserInfo userInfo;
private String customName;
private String model;
private String businessName;
private String planCompleteDate;
private String planUpdateDate;
private String stateDesc;
private String needsDesc;
private String createTime;
private String projProcessType;
// private Set projProcesses = new HashSet(0);
// Constructors
/** default constructor */
public ProjProcess() {
}
/** minimal constructor */
// public ProjProcess(ProjProcess projProcess) {
// this.projProcess = projProcess;
// }
/** full constructor */
public ProjProcess( UserInfo userInfo, String customName, String model, String businessName, String planCompleteDate, String planUpdateDate, String stateDesc, String needsDesc, String createTime, String projProcessType) {
// this.projProcess = projProcess;
this.userInfo = userInfo;
this.customName = customName;
this.model = model;
this.businessName = businessName;
this.planCompleteDate = planCompleteDate;
this.planUpdateDate = planUpdateDate;
this.stateDesc = stateDesc;
this.needsDesc = needsDesc;
this.createTime = createTime;
this.projProcessType = projProcessType;
//this.projProcesses = projProcesses;
}
// Property accessors
public Integer getProjProcessId() {
return this.projProcessId;
}
public void setProjProcessId(Integer projProcessId) {
this.projProcessId = projProcessId;
}
// public ProjProcess getProjProcess() {
// return this.projProcess;
// }
//
// public void setProjProcess(ProjProcess projProcess) {
// this.projProcess = projProcess;
// }
public UserInfo getUserInfo() {
return this.userInfo;
}
public void setUserInfo(UserInfo userInfo) {
this.userInfo = userInfo;
}
public String getCustomName() {
return this.customName;
}
public void setCustomName(String customName) {
this.customName = customName;
}
public String getModel() {
return this.model;
}
public void setModel(String model) {
this.model = model;
}
public String getBusinessName() {
return this.businessName;
}
public void setBusinessName(String businessName) {
this.businessName = businessName;
}
public String getPlanCompleteDate() {
return this.planCompleteDate;
}
public void setPlanCompleteDate(String planCompleteDate) {
this.planCompleteDate = planCompleteDate;
}
public String getPlanUpdateDate() {
return this.planUpdateDate;
}
public void setPlanUpdateDate(String planUpdateDate) {
this.planUpdateDate = planUpdateDate;
}
public String getStateDesc() {
return this.stateDesc;
}
public void setStateDesc(String stateDesc) {
this.stateDesc = stateDesc;
}
public String getNeedsDesc() {
return this.needsDesc;
}
public void setNeedsDesc(String needsDesc) {
this.needsDesc = needsDesc;
}
public String getCreateTime() {
return this.createTime;
}
public void setCreateTime(String createTime) {
this.createTime = createTime;
}
public String getProjProcessType() {
return this.projProcessType;
}
public void setProjProcessType(String projProcessType) {
this.projProcessType = projProcessType;
}
// public Set getProjProcesses() {
// return this.projProcesses;
// }
//
// public void setProjProcesses(Set projProcesses) {
// this.projProcesses = projProcesses;
// }
}
java --------------------编程问答-------------------- 项目加载运行时没有出现这个类。
2013-02-19 10:22:00,784 org.springframework.web.context.support.XmlWebApplicationContext - Bean factory for application context [org.springframework.web.context.support.XmlWebApplicationContext@1b5a40a]: org.springframework.beans.factory.support.DefaultListableBeanFactory@c02a
2013-02-19 10:22:02,775 org.springframework.beans.factory.support.DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@c02a: defining beans [dataSource,sessionFactory,WorkTimeDAO,MessageDAO,BranchInfoDAO,MyNoteDAO,ProjProcessDAO,MeetingInfoDAO,RoleInfoDAO,DepartInfoDAO,RoleRightDAO,RightInfoDAO,ReadCommonMessageDAO,LoginLogDAO,ScheduleDAO,PreContractDAO,ManualSignDAO,MessageTypeDAO,AccessoryFileDAO,FileInfoDAO,OperateLogDAO,UserInfoDAO,FileTypeInfoDAO,MessageToUserDAO,myNote,loginLogBiz,OperateLogBiz,roleInfoBiz,roleRightBiz,rightInfoBiz,myNoteBiz,projProcessBiz,scheduleBiz,preContractBiz,meetingInfoBiz,branchInfoBiz,departInfoBiz,paging,userbiz,userTools,zhuxiaoAction,treeAction,orderAction,deleteLoginLogAction,queryAllLoginLogAction,queryAllOperateLogAction,deleteOperateByIdAction,queryAllRolesAction,addRoleAction,updateRoleConfrimAction,deleteRoleByIdAction,dispatcherRightByIdAction,dispatcherRightByIdConfirmAction,quryAllMyNoteAction,addMyNoteAction,deleteMyNoteByIdAction,updateMyNoteConfrimAction,quryAllMyProjProcessAction,queryAllByUserAction,addMyProjProcessAction,deleteMyProjProcessByIdAction,updateMyProjProcessConfrimAction,getAddSchedulePageAction,getDepartSchedulePageAction,qureyDepartScheduleAction,addScheduleAction,userAction,messagebiz,messagesAction,manualsingbiz,manualsingAction,perbiz,pcaction]; root of factory hierarchy
2013-02-19 10:22:03,257 org.hibernate.cfg.Environment - Hibernate 3.2.5
2013-02-19 10:22:03,272 org.hibernate.cfg.Environment - hibernate.properties not found
2013-02-19 10:22:03,272 org.hibernate.cfg.Environment - Bytecode provider name : cglib
2013-02-19 10:22:03,288 org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
2013-02-19 10:22:04,035 org.hibernate.cfg.HbmBinder - Mapping class: com.thit.oa.bean.WorkTime -> WorkTime
2013-02-19 10:22:04,190 org.hibernate.cfg.HbmBinder - Mapping class: com.thit.oa.bean.Message -> Message
2013-02-19 10:22:04,517 org.hibernate.cfg.HbmBinder - Mapping class: com.thit.oa.bean.BranchInfo -> BranchInfo
2013-02-19 10:22:04,548 org.hibernate.cfg.HbmBinder - Mapping class: com.thit.oa.bean.MyNote -> MyNote
2013-02-19 10:22:04,579 org.hibernate.cfg.HbmBinder - Mapping class: com.thit.oa.bean.MeetingInfo -> MeetingInfo
2013-02-19 10:22:04,626 org.hibernate.cfg.HbmBinder - Mapping class: com.thit.oa.bean.RoleInfo -> RoleInfo
2013-02-19 10:22:04,641 org.hibernate.cfg.HbmBinder - Mapping class: com.thit.oa.bean.DepartInfo -> DepartInfo
2013-02-19 10:22:04,703 org.hibernate.cfg.HbmBinder - Mapping class: com.thit.oa.bean.RoleRight -> RoleRight
2013-02-19 10:22:04,766 org.hibernate.cfg.HbmBinder - Mapping class: com.thit.oa.bean.RightInfo -> RightInfo
2013-02-19 10:22:04,828 org.hibernate.cfg.HbmBinder - Mapping class: com.thit.oa.bean.ReadCommonMessage -> ReadCommonMessage
2013-02-19 10:22:04,875 org.hibernate.cfg.HbmBinder - Mapping class: com.thit.oa.bean.LoginLog -> LoginLog
2013-02-19 10:22:04,906 org.hibernate.cfg.HbmBinder - Mapping class: com.thit.oa.bean.Schedule -> Schedule
2013-02-19 10:22:04,921 org.hibernate.cfg.HbmBinder - Mapping class: com.thit.oa.bean.PreContract -> PreContract
2013-02-19 10:22:04,937 org.hibernate.cfg.HbmBinder - Mapping class: com.thit.oa.bean.ManualSign -> ManualSign
2013-02-19 10:22:04,983 org.hibernate.cfg.HbmBinder - Mapping class: com.thit.oa.bean.MessageType -> MessageType
2013-02-19 10:22:05,014 org.hibernate.cfg.HbmBinder - Mapping class: com.thit.oa.bean.AccessoryFile -> AccessoryFile
2013-02-19 10:22:05,046 org.hibernate.cfg.HbmBinder - Mapping class: com.thit.oa.bean.FileInfo -> FileInfo
2013-02-19 10:22:05,077 org.hibernate.cfg.HbmBinder - Mapping class: com.thit.oa.bean.OperateLog -> OperateLog
2013-02-19 10:22:05,139 org.hibernate.cfg.HbmBinder - Mapping class: com.thit.oa.bean.UserInfo -> UserInfo
2013-02-19 10:22:05,170 org.hibernate.cfg.HbmBinder - Mapping class: com.thit.oa.bean.FileTypeInfo -> FileTypeInfo
2013-02-19 10:22:05,186 org.hibernate.cfg.HbmBinder - Mapping class: com.thit.oa.bean.MessageToUser -> MessageToUser
2013-02-19 10:22:05,201 org.hibernate.cfg.HbmBinder - Mapping collection: com.thit.oa.bean.Message.readCommonMessages -> ReadCommonMessage
2013-02-19 10:22:05,201 org.hibernate.cfg.HbmBinder - Mapping collection: com.thit.oa.bean.BranchInfo.departInfos -> DepartInfo
2013-02-19 10:22:05,201 org.hibernate.cfg.HbmBinder - Mapping collection: com.thit.oa.bean.MeetingInfo.schedules -> Schedule
2013-02-19 10:22:05,201 org.hibernate.cfg.HbmBinder - Mapping collection: com.thit.oa.bean.RoleInfo.userInfos -> UserInfo
2013-02-19 10:22:05,201 org.hibernate.cfg.HbmBinder - Mapping collection: com.thit.oa.bean.RoleInfo.roleRights -> RoleRight
2013-02-19 10:22:05,201 org.hibernate.cfg.HbmBinder - Mapping collection: com.thit.oa.bean.DepartInfo.userInfos -> UserInfo
2013-02-19 10:22:05,201 org.hibernate.cfg.HbmBinder - Mapping collection: com.thit.oa.bean.RightInfo.roleRights -> RoleRight
2013-02-19 10:22:05,201 org.hibernate.cfg.HbmBinder - Mapping collection: com.thit.oa.bean.Schedule.preContracts -> PreContract
2013-02-19 10:22:05,201 org.hibernate.cfg.HbmBinder - Mapping collection: com.thit.oa.bean.MessageType.messages -> Message
2013-02-19 10:22:05,201 org.hibernate.cfg.HbmBinder - Mapping collection: com.thit.oa.bean.MessageType.messageToUsers -> MessageToUser
2013-02-19 10:22:05,201 org.hibernate.cfg.HbmBinder - Mapping collection: com.thit.oa.bean.FileInfo.accessoryFiles -> AccessoryFile
2013-02-19 10:22:05,201 org.hibernate.cfg.HbmBinder - Mapping collection: com.thit.oa.bean.UserInfo.loginLogs -> LoginLog
2013-02-19 10:22:05,201 org.hibernate.cfg.HbmBinder - Mapping collection: com.thit.oa.bean.UserInfo.preContracts -> PreContract
2013-02-19 10:22:05,201 org.hibernate.cfg.HbmBinder - Mapping collection: com.thit.oa.bean.UserInfo.schedules -> Schedule
2013-02-19 10:22:05,217 org.hibernate.cfg.HbmBinder - Mapping collection: com.thit.oa.bean.UserInfo.myNotes -> MyNote
2013-02-19 10:22:05,217 org.hibernate.cfg.HbmBinder - Mapping collection: com.thit.oa.bean.UserInfo.messages -> Message
2013-02-19 10:22:05,217 org.hibernate.cfg.HbmBinder - Mapping collection: com.thit.oa.bean.UserInfo.manualSigns -> ManualSign
2013-02-19 10:22:05,217 org.hibernate.cfg.HbmBinder - Mapping collection: com.thit.oa.bean.UserInfo.readCommonMessages -> ReadCommonMessage
2013-02-19 10:22:05,217 org.hibernate.cfg.HbmBinder - Mapping collection: com.thit.oa.bean.UserInfo.messageToUsers -> MessageToUser
2013-02-19 10:22:05,217 org.hibernate.cfg.HbmBinder - Mapping collection: com.thit.oa.bean.UserInfo.fileInfos -> FileInfo
2013-02-19 10:22:05,217 org.hibernate.cfg.HbmBinder - Mapping collection: com.thit.oa.bean.UserInfo.departInfos -> DepartInfo
2013-02-19 10:22:05,217 org.hibernate.cfg.HbmBinder - Mapping collection: com.thit.oa.bean.UserInfo.operateLogs -> OperateLog
2013-02-19 10:22:05,217 org.hibernate.cfg.HbmBinder - Mapping collection: com.thit.oa.bean.FileTypeInfo.fileInfos -> FileInfo
2013-02-19 10:22:05,217 org.hibernate.cfg.HbmBinder - Mapping collection: com.thit.oa.bean.FileTypeInfo.accessoryFiles -> AccessoryFile
2013-02-19 10:22:05,217 org.springframework.orm.hibernate3.LocalSessionFactoryBean - Building new Hibernate SessionFactory --------------------编程问答-------------------- 弱弱地问下lz,这是什么框架呀,俺是菜鸟,对你这用xml配置数据库感觉很奇怪......
可不可能是数据库的字段与你配的有出入呢?坐等高手解答 --------------------编程问答-------------------- 从提供的信息看,应该是配置文件加载的问题,仔细看映射文件被加载的代码是不是被别人修改过,或者说加载的映射配置文件不是你写的这个,而是隐藏在别的位置了。 --------------------编程问答-------------------- 是SSH --------------------编程问答-------------------- 不会呀,这只是新加的一个功能,我都按着之前功能写的,就是找不到原因,也比对过好多次了。 --------------------编程问答-------------------- 可以连到数据库的,其他功能可以用。 --------------------编程问答-------------------- clear一下 重新在服务器上部署一下工程试试 感觉不像是代码问题 --------------------编程问答-------------------- 是跨年的BUG,肯定clear 过了,电脑都重启过的。 --------------------编程问答-------------------- 把项目冲中间件删除 然后再重新部署下 试试 --------------------编程问答-------------------- <!-- many-to-one name="projProcess" class="com.thit.oa.bean.ProjProcess" update="false" insert="false" fetch="select">
<column name="ProjProcessId" not-null="true" unique="true" />
</many-to-one--> --------------------编程问答-------------------- schema 也都去掉 试试呢?
再重新编译。 --------------------编程问答-------------------- 太神奇了,Hibernate用注解都很多年了,竟然还有人在用xml配置 --------------------编程问答--------------------
<set name="projProcesses" inverse="true">
<key>
<column name="ProjProcessId" not-null="true" unique="true" />
</key>
<one-to-many class="com.thit.oa.bean.ProjProcess" />
</set>
这里是不是掉了一个表名的属性?
table="表名" --------------------编程问答-------------------- 觉得没用。 我把这些删除了,但还是一样。因为出错是没找到射映:
org.hibernate.MappingException: --------------------编程问答-------------------- 还是一样的哦。。肯定是哪里有问题。。 --------------------编程问答-------------------- 下载hibernate源码 把引用jar包干掉,然后断点跟踪。。。。如此即可找到异常处,需慎用。。。 --------------------编程问答-------------------- java的那种代码+XML配置文件的做法爽吗,跳来跳去的,眼花... --------------------编程问答--------------------
注解可读性不高,而且显得代码混乱。主要还是看公司的开发习惯。
楼主把项目重新编译一下。 --------------------编程问答-------------------- 这是新增出的错:
当查询时用:
return getHibernateTemplate().find("from com.thit.oa.bean.ProjProcess as s where s.userInfo.userId="+userInfo.getUserId()+" order by s.createTime desc");
com.thit.oa.bean.ProjProcess 写完整没出这个错。
新增方法:
public void insert(ProjProcess projProcess) throws Exception {
System.out.println(projProcess.getBusinessName()+" "+projProcess.getCustomName());
getHibernateTemplate().save(projProcess);
}
到这句时:就说找不到实体类了。
--------------------编程问答--------------------
既然项目启动加载的时候没有把ProjProcess类成功加载
那么
首先还是考虑hibernate映射的问题;和没有出问题的项目的映射配置对比下,你的配置和我之前写过的有一些差异;
另外
别的工程中是否有引用到过这个实体类,或者别的工程是否有同名的类?
看下新增方法中的ProjProcess类的引用是否正确。
--------------------编程问答-------------------- --------------------编程问答-------------------- 是不是有同名的实体冲突了,改个名字看看 --------------------编程问答-------------------- 又突然好了,也不知道动了那里。
补充:Java , Web 开发