-->
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: insert does not work
PostPosted: Sun Jun 22, 2008 12:14 pm 
Beginner
Beginner

Joined: Mon May 26, 2008 3:34 am
Posts: 31
Hi everyone,

I am trying to make an insert but nothing happens in my database. This is my User class:

Code:
public class User implements Serializable {
   private int id = 0;
   private String login = null;
   private String password = null;
   private Date creationDate = null;
   private Profile profile = null;
   private UserCategory userCategory = null;
   private List<Resource> resourceList = null;
   private List<Item> itemList = null;

                ..................

}


my mapping file:

Code:
<hibernate-mapping package="com.model.user.web" auto-import="false">

<class name="User" table="user" lazy="true">

   <id name="id" type="integer" column="id" unsaved-value="null">
      <generator class="native"/>
   </id>

   <property name="login" type="string" column="login" length="10" not-null="true" unique="true"/>
   <property name="password" type="string" column="password" length="100" not-null="true"/>
   <property name="creationDate" column="creation_date" type="java.util.Date" update="false" not-null="true"/>   

   <one-to-one name="profile" class="Profile" cascade="all" />
   <many-to-one name="userCategory" cascade="none" class="com.model.category.UserCategory" foreign-key="user_fk_id_category">
      <column name="id_category" not-null="false" />
   </many-to-one>

   <list name="resourceList" lazy="true" inverse="true">
      <key column="id_user"/>
      <list-index column="start"/>
      <one-to-many class="com.model.resource.Resource"/>
   </list>

   <list name="itemList" lazy="true" inverse="true">
      <key column="id_user"/>
      <list-index column="start"/>
      <one-to-many class="com.model.item.Item"/>
   </list>

</class>

</hibernate-mapping>


this is my insert makePersistent() method:

Code:
public void makePersistent(User user) throws InfrastructureException {
      try {      
         HibernateUtil.getSession().saveOrUpdate(user);
         HibernateUtil.commitTransaction();
      } catch (HibernateException ex) {
         HibernateUtil.rollbackTransaction();
         throw new InfrastructureException(ex);
      } finally {
         HibernateUtil.closeSession();
        }
   }


Can someone help me? Any idea of what is going on?

Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 23, 2008 3:25 am 
Pro
Pro

Joined: Tue Jun 12, 2007 4:13 am
Posts: 209
Location: Berlin, Germany
I think you should call
Code:
session.beginTransaction()
before calling
Code:
saveOrUpdate
.

_________________
Carlo
-----------------------------------------------------------
please don't forget to rate if this post helped you


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 23, 2008 5:09 am 
Beginner
Beginner

Joined: Mon May 26, 2008 3:34 am
Posts: 31
Yes, i forgot to explain it, i call HibernateUtil.beginTransaction() in the constructor:

Code:
public WebUserDAO() {
      HibernateUtil.beginTransaction();
   }


Any other idea?

Thanks in advance


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.