-->
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.  [ 6 posts ] 
Author Message
 Post subject: Create form / update form
PostPosted: Thu May 06, 2004 10:17 am 
Beginner
Beginner

Joined: Thu May 06, 2004 5:30 am
Posts: 45
Hi,

I've got a form to create a user. This works correctly.
I also have a search functionality so you can search a user and then select him to update him. No problem.

The insertUserForm will be populated with all values.

But when I want to save the user, A new user is created.

What am I missing?


Top
 Profile  
 
 Post subject: Re: Create form / update form
PostPosted: Thu May 06, 2004 11:23 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
-FoX- wrote:
What am I missing?

The doc.
check the unsaved-value keyword

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: Create form / update form
PostPosted: Thu May 06, 2004 4:05 pm 
Beginner
Beginner

Joined: Thu May 06, 2004 5:30 am
Posts: 45
emmanuel wrote:
-FoX- wrote:
What am I missing?

The doc.
check the unsaved-value keyword

I don't think so... I've printed the whole hibernate_reference.pdf :)
But I'll check the unsaved-value keyword.

I don't have the doc with me right now, but do I have to write a different action (struts) to update the user?


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 07, 2004 5:01 am 
Beginner
Beginner

Joined: Thu May 06, 2004 5:30 am
Posts: 45
I can't get it right..

my code:
USERACCOUNT CLASS with method to insert/update user
Code:
public UserAccount insertUserAccount(UserAccount transferUser)
{
   Session session = null;
   Transaction transaction = null;
   
   try
   {
   session = HibernateDAOFactory.currentSession();
   transaction = session.beginTransaction();
   session.saveOrUpdate(transferUser);
   transaction.commit();
   insertBoolean = true;
   HibernateDAOFactory.closeSession();
   }
   catch(HibernateException he)
   {
   log.error(he);
   if(transaction != null)
   {
      log.debug("Rolling back transaction");
      try
      {
      transaction.rollback();   
                                insertBoolean = false;
      }
      catch (HibernateException hte)
      {
      log.error("Error on rolling back transaction");
      }
   }
      he.printStackTrace();            }
   catch(Exception e)
   {
      log.error("Unhandled exception");
      log.error(e);
   }      
   return (insertBoolean == true) ? transferUser : null;
   }


USERACCOUNT.HBM.XML
Code:
<hibernate-mapping>
  <class name="UserAccount" table="USERACCOUNT">
    <id name="id" column="userID" type="int" unsaved-value="null">
      <generator class="increment" />
    </id>
   
    <property name="firstname" type="string" />
    <property name="lastname" type="string" />
    <property name="address" type="string" />
    <property name="zipcode" type="string" />
    <property name="city" type="string" />
    <property name="telephone" type="string" />
    <property name="email" type="string" />
    <property name="username" type="string" />
    <property name="password" type="string" />
    <property name="old_password" type="string" />
    <property name="last_login" type="date" />
    <property name="status" type="string" />
    <property name="companyID" type="int" />
   
  </class>
</hibernate-mapping>


Is it possible to provide me with some kind of example?


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 07, 2004 5:42 am 
Beginner
Beginner

Joined: Tue Aug 26, 2003 9:50 am
Posts: 34
Location: Weiden Opf. / Germany
type="int" and unsaved-value="null" ?

that should work at all, since scalars cannot be null in java. you may wanna change it to "0" instead.

besides check the value of the id property of the transferUser when you're trying to update it. it has to be set to the id of the user you're trying to update.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 07, 2004 5:43 am 
Beginner
Beginner

Joined: Tue Aug 26, 2003 9:50 am
Posts: 34
Location: Weiden Opf. / Germany
sorry, i meant:

that should NOT work at all.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.