Sometimes domainInstance.attach() doesn't work

View: New views
4 Messages — Rating Filter:   Alert me  

Sometimes domainInstance.attach() doesn't work

by tomLee :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Here is my code:
def user = authenticateService.principal().getDomainClass()
        if(user){
           if(!user.isAttached()){
             user = user.attach()
           }
         user = user.refresh
Sometimes user.attach() doesn't work

Want know why this happen?

Thanks

Re: Sometimes domainInstance.attach() doesn't work

by Burt Beckwith :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Use this instead:

   def user = User.get(authenticateService.principal().domainClass.id)

Burt

>
> Here is my code:
> def user = authenticateService.principal().getDomainClass()
>         if(user){
>            if(!user.isAttached()){
>              user = user.attach()
>            }
>          user = user.refresh
> Sometimes user.attach() doesn't work
>
> Want know why this happen?
>
> Thanks
>


signature.asc (204 bytes) Download Attachment

Re: Sometimes domainInstance.attach() doesn't work

by tomLee :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks, this should work.

Burt Beckwith wrote:
Use this instead:

   def user = User.get(authenticateService.principal().domainClass.id)

Burt

>
> Here is my code:
> def user = authenticateService.principal().getDomainClass()
>         if(user){
>            if(!user.isAttached()){
>              user = user.attach()
>            }
>          user = user.refresh
> Sometimes user.attach() doesn't work
>
> Want know why this happen?
>
> Thanks
>

 

Re: Sometimes domainInstance.attach() doesn't work

by ianroberts :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Burt Beckwith wrote:
> Use this instead:
>
>    def user = User.get(authenticateService.principal().domainClass.id)

That's all very well, but the trouble with that although user and
principal().domainClass refer to the same entity in the database they
are different object references.  I can make changes to user and save it
to the database but the changes won't be reflected in the principal
until the user logs out and in again.  Re-attaching the existing object
instead means that changes take effect immediately.

Ian

--
Ian Roberts               | Department of Computer Science
i.roberts@...  | University of Sheffield, UK

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email