Hola a todo, soy nuevo en el tema de java.
Estoy armando una aplicación con struts y hibernate y me ha surgido un problema.
Les escribo a ver si alguien me puede ayudar.
Tengo una tabla de usuarios con estructura de padre e hijo.
Donde
“id” es el identificador de usuario y “id_usuari” es el id del padre
CREATE TABLE `usuaris` (
`id` int(10) unsigned NOT NULL auto_increment,
`usuaris_id` int(10) unsigned NOT NULL,
`nom` varchar(255) default NULL,
`cognoms` varchar(255) default NULL,
`alies` varchar(20) NOT NULL,
`email` varchar(255) NOT NULL,
`telefon` varchar(45) default NULL,
`clau` varchar(255) NOT NULL,
`created` timestamp NULL default NULL,
`last_updated` timestamp NULL default NULL,
PRIMARY KEY (`id`),
KEY `usuaris_FKIndex1` (`usuaris_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Tengo el siguiente pojo
public class Usuari implements Serializable{
private static final long serialVersionUID = 8369458909806196675L;
private Integer id;
private String nom;
private String cognoms;
private String alies;
private String email;
private String telefon;
private String clau;
private Date created;
private Date lastUpdated;
private Usuari usuarisId;
public Usuari getUsuarisId() {
return usuarisId;
}
public void setUsuarisId(Usuari usuarisId) {
this.usuarisId = usuarisId;
}
public String getClau() {
return clau;
}
public void setClau(String clau) {
this.clau = clau;
}
public String getCognoms() {
return cognoms;
}
public void setCognoms(String cognoms) {
this.cognoms = cognoms;
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Date getLastUpdated() {
return lastUpdated;
}
public void setLastUpdated(Date lastUpdated) {
this.lastUpdated = lastUpdated;
}
public String getTelefon() {
return telefon;
}
public void setTelefon(String telefon) {
this.telefon = telefon;
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public String getAlies() {
return alies;
}
public void setAlies(String alies) {
this.alies = alies;
}
}
y el siguiente mapping
<hibernate-mapping>
<class name="com.caya.pojos.Usuari" table="usuaris">
<id name="Id" column="id">
<generator class="native"></generator>
</id>
<property name="nom" column="nom"></property>
<property name="cognoms" column="cognoms"></property>
<property name="alies" column="alies"></property>
<property name="email" column="email"></property>
<property name="telefon" column="telefon"></property>
<property name="clau" column="clau"></property>
<property name="created" type="timestamp" column="created"></property>
<property name="lastUpdated" type="timestamp" column="last_updated"></property>
<many-to-one name="usuarisId" class="com.caya.pojos.Usuari" lazy="false">
<column name="usuaris_id"></column>
</many-to-one>
</class>
</hibernate-mapping>
Y este es el error
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: No row with the given identifier exists: [com.caya.pojos.Usuari#0]
org.apache.struts.chain.ComposableRequestProcessor .process(ComposableRequestProcessor.java:286)
org.apache.struts.action.ActionServlet.process(Act ionServlet.java:1913)
org.apache.struts.action.ActionServlet.doPost(Acti onServlet.java:462)
javax.servlet.http.HttpServlet.service(HttpServlet .java:710)
javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
root cause
org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.caya.pojos.Usuari#0]
org.hibernate.impl.SessionFactoryImpl$1.handleEnti tyNotFound(SessionFactoryImpl.java:375)
org.hibernate.event.def.DefaultLoadEventListener.l oad(DefaultLoadEventListener.java:145)
org.hibernate.event.def.DefaultLoadEventListener.p roxyOrLoad(DefaultLoadEventListener.java:195)
org.hibernate.event.def.DefaultLoadEventListener.o nLoad(DefaultLoadEventListener.java:103)
org.hibernate.impl.SessionImpl.fireLoad(SessionImp l.java:878)
org.hibernate.impl.SessionImpl.internalLoad(Sessio nImpl.java:846)
org.hibernate.type.EntityType.resolveIdentifier(En tityType.java:557)
org.hibernate.type.EntityType.resolve(EntityType.j ava:379)
org.hibernate.engine.TwoPhaseLoad.initializeEntity (TwoPhaseLoad.java:116)
org.hibernate.loader.Loader.initializeEntitiesAndC ollections(Loader.java:842)
org.hibernate.loader.Loader.doQuery(Loader.java:71 7)
org.hibernate.loader.Loader.doQueryAndInitializeNo nLazyCollections(Loader.java:224)
org.hibernate.loader.Loader.doList(Loader.java:221 1)
org.hibernate.loader.Loader.listIgnoreQueryCache(L oader.java:2095)
org.hibernate.loader.Loader.list(Loader.java:2090)
org.hibernate.loader.hql.QueryLoader.list(QueryLoa der.java:388)
org.hibernate.hql.ast.QueryTranslatorImpl.list(Que ryTranslatorImpl.java:338)
org.hibernate.engine.query.HQLQueryPlan.performLis t(HQLQueryPlan.java:172)
org.hibernate.impl.SessionImpl.list(SessionImpl.ja va:1121)
org.hibernate.impl.QueryImpl.list(QueryImpl.java:7 9)
com.caya.daos.UsuariDao.authUsuari(UsuariDao.java: 44)
com.caya.bos.UsuariBo.authUsuari(UsuariBo.java:48)
com.caya.actions.LoginAction.auth(LoginAction.java :61)
sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.apache.struts.actions.DispatchAction.dispatchM ethod(DispatchAction.java:269)
org.apache.struts.actions.DispatchAction.execute(D ispatchAction.java:170)
org.apache.struts.chain.commands.servlet.ExecuteAc tion.execute(ExecuteAction.java:58)
org.apache.struts.chain.commands.AbstractExecuteAc tion.execute(AbstractExecuteAction.java:67)
org.apache.struts.chain.commands.ActionCommandBase .execute(ActionCommandBase.java:51)
org.apache.commons.chain.impl.ChainBase.execute(Ch ainBase.java:190)
org.apache.commons.chain.generic.LookupCommand.exe cute(LookupCommand.java:304)
org.apache.commons.chain.impl.ChainBase.execute(Ch ainBase.java:190)
org.apache.struts.chain.ComposableRequestProcessor .process(ComposableRequestProcessor.java:283)
org.apache.struts.action.ActionServlet.process(Act ionServlet.java:1913)
org.apache.struts.action.ActionServlet.doPost(Acti onServlet.java:462)
javax.servlet.http.HttpServlet.service(HttpServlet .java:710)
javax.servlet.http.HttpServlet.service(HttpServlet .java:803)