我正在使用Spring使用Spring进行应用程序,我遇到了以下错误,我不知道如何处理它。
现在我在控制台中收到此消息:
SELECT t1.id,
t2.id,
CASE
WHEN t1.id IS NOT NULL
AND t2.id IS NOT NULL
THEN 'ID in both sources'
WHEN t1.id IS NULL
THEN 'ID in T2 only'
WHEN t2.id IS NULL
THEN 'ID in T1 only'
END source_key
FROM t1
FULL OUTER JOIN t2
ON t1.id = t2.id
WHERE t1.id = 1 -- your test_id here
OR t2.id = 1; -- your test_id here
这是我的ImportController类
org.hibernate.TypeMismatchException: Provided id of the wrong type. Expected: class java.lang.Integer, got class java.lang.String
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:86)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
at org.hibernate.impl.SessionImpl.load(SessionImpl.java:795)
at org.hibernate.impl.SessionImpl.load(SessionImpl.java:788)
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.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
at com.sun.proxy.$Proxy11.load(Unknown Source)
at com.my.dao.DepartementImplDB.getDepartementByNom(DepartementImplDB.java:54)
at com.my.dao.DepartementImplDB.addDepartement(DepartementImplDB.java:29)
at com.my.service.DepartementImplMetier.create(DepartementImplMetier.java:57)
at com.my.controller.ImportController.Read(ImportController.java:279)
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.springframework.web.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:710)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:167)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:414)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:402)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:563)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:617)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1521)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1478)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
这是我的Employe.hbm.xml
/**
* @author Ilias
*/
package com.my.controller;
//import ...
import com.my.dao.Departement;
@Controller
public class ImportController {
DepartementImplMetier dbD = new DepartementImplMetier();
@RequestMapping(value="/read")
public String Read(Model model,@RequestParam CommonsMultipartFile[] fileUpload)
throws IOException, EncryptedDocumentException, InvalidFormatException, java.text.ParseException
{
liste = extraire(modelnom);
for(int m=0, i=29;i<liste.size();i=i+29){//i=i+29
Employe employe= new Employe();
Departement departement = new Departement();
if(i % 29 == 0) m++;
//... Some code here
String dep = (String)liste.get(29*m+13).toString();
Departement d = new Departement();
departement.setNomDepartement(dep);
boolean bool=true;
List<Departement> departements = dbD.getAll();
boolean depbool = true;
for(int j=0;j< departements.size();j++){
if(departements.get(j).getNomDepartement() == dep )
{
depbool = false;
}
if(depbool){
try {
dbD.create(departement);
} catch (Throwable e) {
e.printStackTrace();
}
}
}
for(int n=0;n<employes.size();n++){
if(employes.get(n).getMatriculeMY() == (int)mat )
{
bool= false;
}
}
if(bool){
try {
dbD.create(departement);
dbE.create(employe);
} catch (Throwable e) {
e.printStackTrace();
}
}
}
}
return "redirect";
}}
}
这是我的Departement.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 5 ao?t 2015 11:05:44 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="com.my.dao.Employe" table="EMPLOYE">
<id name="id" type="int">
<column name="ID" />
<generator class="native" />
</id>
<property name="nomEmploye" type="java.lang.String">
<column name="NOMEMPLOYE" />
</property>
<property name="prenomEmploye" type="java.lang.String">
<column name="PRENOMEMPLOYE" />
</property>
<property name="matriculeMY" type="int">
<column name="MATRICULEMY" />
</property>
<property name="adresse" type="java.lang.String">
<column name="ADRESSE" />
</property>
<property name="sexe" type="java.lang.String">
<column name="SEXE" />
</property>
<property name="cin" type="java.lang.String">
<column name="CIN" />
</property>
<property name="dateNaissance" type="java.lang.String">
<column name="DATENAISSANCE" />
</property>
<property name="situationFamiliale" type="java.lang.String">
<column name="SITUATIONFAMILIALE" />
</property>
<property name="dateEntree" type="java.lang.String">
<column name="DATEENTREE" />
</property>
<property name="dateSortie" type="java.lang.String">
<column name="DATESORTIE" />
</property>
<property name="numCIMR" type="java.lang.String">
<column name="NUMCIMR" />
</property>
<property name="numCNSS" type="java.lang.String">
<column name="NUMCNSS" />
</property>
<property name="numMUT" type="java.lang.String">
<column name="NUMMUT" />
</property>
<property name="profile" type="java.lang.String">
<column name="PROFILE" />
</property>
<property name="resteConge" type="java.lang.String">
<column name="RESTECONGE" />
</property>
<property name="banque" type="java.lang.String">
<column name="BANQUE" />
</property>
<property name="numCpteBanc" type="java.lang.String">
<column name="NUMCPTEBANC" />
</property>
<!-- <property name="fonction" type="java.lang.String">
<column name="FONCTION" />
</property> -->
<property name="salaire" type="float">
<column name="SALAIRE" />
</property>
<property name="indTransport" type="float">
<column name="INDTRANSPORT" />
</property>
<property name="indRepresent" type="float">
<column name="INDREPRESENT" />
</property>
<property name="indPanier" type="float">
<column name="INDPANIER" />
</property>
<many-to-one name="eDepartement" class="com.my.dao.Departement" access="field" fetch="join">
<column name="EDEPARTEMENT" />
</many-to-one>
<many-to-one name="eFonction" class="com.my.dao.Fonction" access="field" fetch="join">
<column name="EFONCTION" />
</many-to-one>
<many-to-one name="eService" class="com.my.dao.Service" access="field" fetch="join">
<column name="ESERVICE" />
</many-to-one>
<many-to-one name="eTypePaiement" class="com.my.dao.TypePaiement" access="field" fetch="join">
<column name="ETYPEPAIEMENT" />
</many-to-one>
<many-to-one name="eModePaiement" class="com.my.dao.ModePaiement" access="field" fetch="join">
<column name="EMODEPAIEMENT" />
</many-to-one>
</class>
</hibernate-mapping>
在调试之后,问题就在这里:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 5 ao?t 2015 11:05:44 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="com.my.dao.Departement" table="DEPARTEMENT">
<id name="id" type="int">
<column name="ID" />
<generator class="native" />
</id>
<property name="nomDepartement" type="java.lang.String">
<column name="NOMDEPARTEMENT" />
</property>
<set name="Employe" inverse="true">
<key column="ID" not-null="true"/>
<one-to-many class="com.my.dao.Employe" />
</set>
</class>
</hibernate-mapping>
在这里:
boolean depbool = true;
for(int j=0;j< departements.size();j++){
if(departements.get(j).getNomDepartement() == dep )
{
depbool = false;
}
if(depbool){
try {
dbD.create(departement);
} catch (Throwable e) {
e.printStackTrace();
}
}
}
这个DepartementImplDB类
dbD.create(departement);
答案 0 :(得分:2)
你的问题真是一团糟......但如果你读了例外:
提供错误类型的ID。 预期:类java.lang。整数,得到类 java.lang。字符串
Anf看了你的Departement
类之后,它只有2个字段和一个集合(根据hibernate映射):
int id;
String nomDepartament;
Set employees;
这只是意味着,您在代码中的某处传递了nomDepartament
字段而不是id
...
但就你没有提供的那样,Departement
类或DepartementImplMetier.create()
方法,导致异常的方法我不能多说......
所以...... start here关注你的问题,并只提供代码的重要部分。