argument type mismatch
错误信息:org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of com.chinasei.hibernate.model.SchoolMaster.schoolID
at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:128)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.setIdentifier(AbstractEntityTuplizer.java:227)
at org.hibernate.persister.entity.AbstractEntityPersister.setIdentifier(AbstractEntityPersister.java:3610)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:194)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:144)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:563)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:551)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:547)
at com.chinasei.hibernate.dao.SchoolMasterDAO.save(SchoolMasterDAO.java:21)
at org.apache.jsp.School_jsp._jspService(School_jsp.java:75)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:66)
... 32 more
2013-12-6 13:47:07 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet jsp threw exception
java.lang.IllegalArgumentException: argument type mismatch
SchoolMasterDAO.java如下:
package com.chinasei.hibernate.dao;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Example;
import com.chinasei.hibernate.model.SchoolMaster;
public class SchoolMasterDAO extends BaseHibernateDAO{
private static final Log log = LogFactory.getLog(SchoolMasterDAO.class);
public void save(SchoolMaster transientInstance) {
log.debug("saving Students instance");
Session session = getSession();
Transaction tx = null;
try{
tx = session.beginTransaction();
session.save(transientInstance);
tx.commit();
log.debug("save successful");
}catch(RuntimeException re){
log.error("save failed",re);
if(tx!=null){
tx.rollback();
}
re.printStackTrace();
throw re;
}finally{
session.close();
}
}
public List findByExample(SchoolMaster instance) {
log.debug("finding Course instance by example");
try {
List results = getSession().createCriteria(
"com.chinasei.hibernate.dao.Course").add(
Example.create(instance)).list();
log.debug("find by example successful, result size: "
+ results.size());
return results;
} catch (RuntimeException re) {
log.error("find by example failed", re);
throw re;
}
}
}
SchoolMaster.hbm.xml如下:
<hibernate-mapping>
<class name="com.chinasei.hibernate.model.School" table="SCHOOL" schema="dbo" catalog="chinasei">
<id name="schoolID" type="int">
<column name="SCHOOL_ID" precision="38" scale="0"/>
</id>
<property name="schoolName" type="string">
<column name="SCHOOL_NAME" length="50" not-null="true"/>
</property>
<property name="schoolAddress" type="string">
<column name="SCHOOL_ADDRESS" length="100" not-null="true"/>
</property>
</class>
<class name="com.chinasei.hibernate.model.SchoolMaster" table="SchoolMaster" schema="dbo" catalog="chinasei">
<id name="schoolID" type="int">
<column name="SCHOOL_ID" precision="38" scale="0"/>
<generator class="foreign">
<param name="property">school</param>
</generator>
</id>
<property name="masterName" type="string">
<column name="MASTER_NAME" length="50" not-null="true"/>
</property>
<one-to-one name="school" class="com.chinasei.hibernate.model.School" constrained="true" cascade="all"/>
</class>
</hibernate-mapping>
SchoolMaster.java如下:
package com.chinasei.hibernate.model;
public class SchoolMaster implements java.io.Serializable{
public void setSchoolID(int schoolID) {
this.schoolID = schoolID;
}
public long getSchoolID() {
return schoolID;
}
public School getSchool() {
return school;
}
public void setSchool(School school) {
this.school = school;
}
public String getMasterName() {
return masterName;
}
public void setMasterName(String masterName) {
this.masterName = masterName;
}
private int schoolID;
private String masterName;
private School school;
}
School.java如下:
package com.chinasei.hibernate.model;
public class School implements java.io.Serializable{
public void setSchoolID(int schoolID) {
this.schoolID = schoolID;
}
public long getSchoolID() {
return schoolID;
}
public String getSchoolName() {
return schoolName;
}
public void setSchoolName(String schoolName) {
this.schoolName = schoolName;
}
public String getSchoolAddress() {
return schoolAddress;
}
public void setSchoolAddress(String schoolAddress) {
this.schoolAddress = schoolAddress;
}
private int schoolID;
private String schoolName;
private String schoolAddress;
}
--------------------编程问答--------------------
public void setSchoolID(int schoolID) {
this.schoolID = schoolID;
}
public long getSchoolID() {
return schoolID;
}
这个类型到底是啥类型的呀 --------------------编程问答-------------------- 类型不匹配,一个是int一个是long
补充:Java , Eclipse