-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Problem with load method
PostPosted: Thu Nov 13, 2003 9:54 am 
Beginner
Beginner

Joined: Thu Oct 02, 2003 8:02 am
Posts: 45
I have a Utilisateur class and a login class with the following file mapping :

<class name="com.cfort.utilisateur.Login" table="login">
<id name="id" column="identifiant" type="string" length="20">
<generator class="assigned"/>
</id>
<property name="motPasse" type="string" length="20"/>
<property name="dernierLogin" type="date"/>
<one-to-one name="utilisateur" class="com.cfort.utilisateur.Utilisateur"/>
</class>

<class name="com.cfort.utilisateur.Utilisateur" table="utilisateur" discriminator-value="U">
<id name="id" column="identifiant" type="string" length="20">
<generator class="assigned"/>
</id>
<discriminator column="type" type="character"/>
<property name="dateAbonnement" type="date"/>
<property name="datePaiement" type="date"/>
<property name="modeReglement">
<column name="modeReglement" sql-type="varchar(30)"/>
</property>
<property name="nbPoints" type="integer"/>
<one-to-one name="login" class="com.cfort.utilisateur.Login"/>
<subclass name="com.cfort.utilisateur.Particulier" discriminator-value="P">
<property name="nom" type="string" length="30"/>
<property name="prenom" type="string" length="30"/>
<property name="dateNaissance" type="date"/>
</subclass>
<subclass name="com.cfort.utilisateur.Entreprise" discriminator-value="U">
<property name="raisonSociale" type="string" length="60"/>
<property name="nbSalarie" type="integer"/>
<property name="numInsee" type="string" length="20"/>
</subclass>

</class>

When i insert a new user, i need to know if the id already exists. So i write the code below :
Code:
public boolean existe(String id)
{
   try
         {
            Session session = HibernateDAOFactory.creerConnection();
            Transaction tx = session.beginTransaction();
            Utilisateur u = (Utilisateur) session.load(Utilisateur.class, id);
                        tx.commit();
            if (u == null)
               return false;
            else
               return true;   
            
         }
         catch(Exception e)
         {
            e.printStackTrace();
            return false;
         }
   
}


When i execute the method, i have the following error message

INFO: Query language substitutions: {}
Hibernate: select login1_.identifiant as identifiant0_, login1_.motPasse as motPasse0_, login1_.dernierLogin as dernierL3_0_, utilisat0_.identifiant as identifiant1_, utilisat0_.type as type1_, utilisat0_.dateAbonnement as dateAbon3_1_, utilisat0_.datePaiement as datePaie4_1_, utilisat0_.modeReglement as modeRegl5_1_, utilisat0_.nbPoints as nbPoints1_, utilisat0_.nom as nom1_, utilisat0_.prenom as prenom1_, utilisat0_.dateNaissance as dateNais9_1_, utilisat0_.raisonSociale as raisonS10_1_, utilisat0_.nbSalarie as nbSalarie1_, utilisat0_.numInsee as numInsee1_ from utilisateur utilisat0_ left outer join login login1_ on utilisat0_.identifiant=login1_.identifiant where utilisat0_.identifiant=?
net.sf.hibernate.ObjectNotFoundException: No row with the given identifier exists: jean, of class: com.cfort.utilisateur.Utilisateur
at net.sf.hibernate.impl.SessionImpl.throwObjectNotFound(SessionImpl.java:1678)
at net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1689)
at com.cfort.dao.HibernateUtilisateurDAO.existe(HibernateUtilisateurDAO.java:79)
at com.cfort.service.UtilisateurService.inscrire(UtilisateurService.java:26)
at com.cfort.struts.action.InscrireAction.execute(InscrireAction.java:68)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:284)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:204)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:563)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:245)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:199)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:563)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:195)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:164)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:149)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:563)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:156)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:563)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:972)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:209)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:670)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:517)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:575)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:666)
at java.lang.Thread.run(Thread.java:534)
Hibernate: insert into utilisateur (nom, prenom, dateNaissance, dateAbonnement, datePaiement, modeReglement, nbPoints, type, identifiant) values (?, ?, ?, ?, ?, ?, ?, 'P', ?)
Hibernate: insert into login (motPasse, dernierLogin, identifiant) values (?, ?, ?)

Can someone explain to me the meaning of the error and how can i test
if a record with the id typed is already store in the DataBase

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 13, 2003 10:13 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Read the JavaDoc.


In Hibernate 2.1, you may use the get() method as you have tried to use load() here.

In 2.0, we tell you to write a query.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 13, 2003 10:21 am 
Senior
Senior

Joined: Tue Sep 23, 2003 8:18 am
Posts: 137
Location: Johannesburg, South Africa
Although many would probably say...don't do it, you could very well just put your load inside a try-catch, that catches the 'net.sf.hibernate.ObjectNotFoundException' exception and handles that the same as a false.

I personally use the query option Gavin described, because your session may become unstable in the exception.

btw. I recommend you have a finally, that closes the session you created.

-G


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.