-->
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.  [ 1 post ] 
Author Message
 Post subject: maintaing transactions
PostPosted: Thu Feb 03, 2005 3:19 am 
Beginner
Beginner

Joined: Thu Dec 02, 2004 4:49 am
Posts: 32
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:2.1.7

Mapping documents:

<class name="User" table="USER_DETAIL">
<id name="id" type="long" column="USER_ID">
<generator class="native" />
</id>
<property name="loginId" type="string" length="15"
column="LOGIN_ID" not-null="true">
</property>
<set name="rolesSet" table="USER_ROLE_MAP" access="field">
<key column="USER_ID" />
<many-to-many column="ROLE_ID" class="Role" />
</set>
</class>

<class name="Role" table="ROLE">
<id name="id" type="long" column="ROLE_ID">
<generator class="native" />
</id>
<property name="name" type="string" length="50"
column="ROLE_NAME" not-null="true" />
</class>


Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

Hi,

I am writing a webservice using axis, spring and hibernate.
In the application I have follwoing methods

createUser(name);
addRoleToUser(userid, roleid);

copyUser(id,name);

If I copy a user, i need to create a new user with all the attributes copied from the existing user.

Code:
createUser(name) {
User user = new User();
user.setName(name);
dao.createUser(user);
}

addRoleToUser(userId, roleId) {
  User = getUser(userId)
   role = getRole(roleId);
   user.addRole(role);
   dao.updateUser(user);
}

copyUser(id, name) {
    User existingUser = getUser(id);
    createUser(name);
   Role[] roles = exisitingUser.getRoles();

    for (int i = 0; i < roles.length; i++) {
       addRoleToUser(newUserId, roles[i].getId());
    }
}


my DAO looks like this:

Code:
createUser(User user) {
getHibernateTemplate().save(user);
}

updateUser(User user) {
getHibernateTemplate().update(user);
}



In the above code for copyUser , I am doing creating and updating in different DAO methods which means different transactions. but I want to maintain a transaction for the whole copy method.

How do I do that?

Any help is appreciated...

Thanks
SSSS


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

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.