mysql で値を検索しようとするとエラーが発生する
これがサーブレットです
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// Obtención de la sesión con Hibernate 4.x
Configuration configuration = new Configuration().configure();
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties())
.buildServiceRegistry();
SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
Session session = sessionFactory.openSession();
BuscaCorreo(session);
}
private static void BuscaCorreo(Session session) {
int id = 1;
LoginDAO loginDAO = new LoginDAO(session);
Login login = new Login();
login.setId(id);
loginDAO.find(login);
System.out.println(login.getCorreo());
}
これは、すべてが取得および設定されている場合のログイン クラスです。
@Entity
public class Login implements Serializable { private static final long serialVersionUID = 7698531046982304548L;
@Id
private long id;
private String correo;
private String clave;
public Login(){
}
public Login(long id, String correo, String clave) {
super();
this.id = id;
this.correo = correo;
this.clave = clave;
}
public String getCorreo() {
return correo;
}
public void setCorreo(String correo) {
this.correo = correo;
}
public String getClave() {
return clave;
}
public void setClave(String clave) {
this.clave = clave;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
これは、mysql に接続したときのクラス LoginDAO です。
private Session session;
public LoginDAO(Session session) {
this.session = session;
}
public String find(Login id) {
String login = null;
try {
login = (String) session.load(Login.class, id);
} catch (Exception e) {
e.printStackTrace();
}
return login;
}
アプリケーションを実行すると、このエラーが発生します
log4j:WARN No appenders could be found for logger (org.jboss.logging).
log4j:WARN Please initialize the log4j system properly.
org.hibernate.TypeMismatchException: Provided id of the wrong type for class com.utp.soft6.model.enteties.Login. Expected: class java.lang.Long, got class com.utp.soft6.model.enteties.Login
null
at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:132)
at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1079)
at org.hibernate.internal.SessionImpl.access$2200(SessionImpl.java:172)
at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.getReference(SessionImpl.java:2402)
at org.hibernate.internal.SessionImpl.load(SessionImpl.java:967)
at com.utp.soft6.model.LoginDAO.find(LoginDAO.java:26)
at com.utp.soft6.hola.BuscaCorreo(hola.java:65)
at com.utp.soft6.hola.doGet(hola.java:47)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)