Not able to save the data to new table

15 views
Skip to first unread message

bellammal...@gmail.com

unread,
Jul 7, 2014, 5:28:58 AM7/7/14
to open...@googlegroups.com
Hi Team,

Can you please sugget on my post bellow..

I want to save  the User data which is going to o_userproperty to o_userdetails too by webservice bt taking new method.I have put all the data into My POJO and i have called




<class name="org.olat.user.UserLmsImplement" table="o_userdetails">  
<id name="key" column="id" type="long" unsaved-value="null">
<generator class="hilo"/>
</id>  
<property name="fk_user_id" type="long" />
<property name="firstName" />
<property name="lastName"/>
<property name="email"/>
                              ..................
                             .................


<property name="orgName"/>
   <property name="usertype" type="boolean"/>
</class> 


My service bellow

@PUT
@Path("musers")
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Response createmultipleUsers(UserData userlist, @Context HttpServletRequest request) {

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

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


userLmsImpl.setEmail(user.getEmail());
userLmsImpl.setCity(user.getCity());
userLmsImpl.setCountry(user.getCoutry());
userLmsImpl.setProject_id(user.getProjectId());
userLmsImpl.setLocation(user.getLocationType());
userLmsImpl.setVertical(user.getVertical());
UserManager um = UserManager.getInstance();
um.createDummyUser(userLmsImpl);
...
}

My method to save the data here

public UserLms createDummyUser(UserLmsImplement userLmsImpl){
dbInstance.getCurrentEntityManager().persist(userLmsImpl);
UserLms newUser = (UserLms)userLmsImpl;
return newUser;
}

I am not getting any exception here,but not able to save the Data into my o_userdetails table

Please help out

Thanks!
Mallikarjuna

Stéphane Rossé

unread,
Jul 7, 2014, 2:05:15 PM7/7/14
to open...@googlegroups.com, bellammal...@gmail.com
Hi

Make sur you commit your changes on the database by calling dbInstance.getCurrentEntityManager().commit()

Best Regards
Stéphane rossé

bellammal...@gmail.com

unread,
Jul 8, 2014, 2:19:11 AM7/8/14
to open...@googlegroups.com, bellammal...@gmail.com
Hi,
It is working,but am inserting row by row,1st row is inserting successfully,but while inserting 2nd row in the loop,2nd record values are updating to 1st record ,i want to be insert 2nd record also with new Id.Here is my loop will iterate n no.of times = n no.of rows
List<UserVO> userData = userlist.getUserList();
ErrorVO[] errorVos = null;
UserLmsImplement  userLmsImpl = new UserLmsImplement();
for(UserVO user : userData  )
{
.................................
...................................
System.out.println(""+identity.getUser().getKey());
userLmsImpl.setFk_user_id(identity.getUser().getKey());
userLmsImpl.setEmail(user.getEmail());
userLmsImpl.setCity(user.getCity());
userLmsImpl.setCountry(user.getCoutry());
userLmsImpl.setProject_id(user.getProjectId());
userLmsImpl.setLocation(user.getLocationType());
userLmsImpl.setVertical(user.getVertical());
DBFactory.getInstance().getCurrentEntityManager().persist(userLmsImpl);

DBFactory.getInstance().commit();
................
......................

}
Please sugget....

Thanks!
Mallikarjuna 

Stéphane Rossé

unread,
Jul 8, 2014, 4:04:04 AM7/8/14
to open...@googlegroups.com, bellammal...@gmail.com
Hi

You must create a UserLmsImplement  per row and persist it, you cannot reuse it. As I see your code, you init

UserLmsImplement  userLmsImpl = new UserLmsImplement();

And than you make a loop with the new users to persist. Create a UserLmsImplement per UserVO and persist it.

Best Regards
Stéphane rossé

bellammal...@gmail.com

unread,
Jul 8, 2014, 4:52:23 AM7/8/14
to open...@googlegroups.com, bellammal...@gmail.com
Thank you so much! am fine now.
Reply all
Reply to author
Forward
0 new messages