cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joe Baldwin <jfbald...@earthlink.net>
Subject Re: Getting null instead of the actual value
Date Tue, 06 Sep 2011 17:03:06 GMT
Christian

BTW, the "totally easy" was not a smart-alec remark. :)

I think it is essential to note that you have to do 3 steps: get your ObjectContext, create
the new entity using the "newObject" method, and then eventually "commitChanges".  My experience
has been that if you do not do these three steps then the "new object" will disappear (even
though it looks like it is persisted, it may only be an illusion).

Joe




On Sep 6, 2011, at 12:44 PM, Christian Grobmeier wrote:

> Joe,
> 
>> It is a tad difficult to follow all of your pseudo-code (as with all pseudo-code),
but it appears that you are adding to "UserRoles" object via Cayenne and that you have left
out the step to "commitChanges" on your ObjectContext.
>> 
>> Here is the basic pseudo code for Cayenne usage model:
>> 
>> 1. get your ObjectContext (ex: BaseContext.getThreadObjectContext();)
>> 2. create a new entity on the OC (ex: (UserRoles)oc.newObject(UserRoles.class);)
>> 3. initialize your entity with values
>> 4. commit changes (ex: oc.commitChanges();)
>> 
>> Totally easy! :)
> 
> hehehe I agree it is totally easy and I must say I have called
> commitChanges but it didn't work - thats why I felt so dumb :-)
> 
> Thanks for looking in my hard to read example - I already see another
> valuable tipp in the thread
> 
> Cheers
> 
>> 
>> Joe
>> 
>> 
>> 
>> On Sep 6, 2011, at 11:14 AM, Christian Grobmeier wrote:
>> 
>>> Folks,
>>> 
>>> I need your help. An error in my app bugs me and I am looking
>>> desperately were it could happen.
>>> 
>>> The use case is:
>>> - create a user
>>> - create a user_role object
>>> - select one of the existing roles
>>> - connect all together and commit
>>> 
>>> I see that all values are correct in the database (mysql console)
>>> 
>>> But after the user registered, my app fails with the error "no role".
>>> 
>>> What I do is basically:
>>> 
>>> ur = User.getUserRoles();
>>> foreach ur:
>>>   r = ur.getRole()
>>> 
>>> 
>>> And the r reference is null. I am not sure what I am doing wrong. Any
>>> hints what I could check in my Cayenne app?
>>> 
>>> I add a role to a user liek this:
>>> 
>>> User user ...
>>> 
>>> UserRoles userRoles = new UserRoles();
>>> userRoles.setUser(user);
>>> userRoles.setRole(role);
>>> user.addToUserRoles(userRoles);
>>> role.addToRolesToJoin(userRoles);
>>> 
>>> Any hints highly apprecitated - thanks in advance
>>> 
>>> Christian
>> 
>> 
> 
> 
> 
> -- 
> http://www.grobmeier.de


Mime
View raw message