[appengine-java] Re: Failure to write objects to HttpSession - NotSerializableException : LazyResult

2010-06-03 Thread Shawn Draper
Attached is the User object...

package com.gcf.core;

import java.util.*;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.NotPersistent;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;




/**
 * Individual user access object that grants access to the site/
application under the ownership of
 * a specified Account.  Additional utility methods are provided to
deliver enhanced and extendible
 * capability beyond the base requirements.
 *
 * @author smd0772
 *
 */
@PersistenceCapable
public class User  implements java.io.Serializable
{

/** Unique serial version id for this class */
@NotPersistent
private static final long serialVersionUID = 386273711850256872L;



/** Unique User ID ID */
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;

/** Full name of the user */
@Persistent
private String fullName;

/** Username or login ID - used for authentication */
@Persistent
private String userName;

/** Password - used for authentication */
@Persistent
private String password;

/** Indicates the Account this user is associated with */
@Persistent
private long accountid;

/** Indicates the security group this user is associated with */
@Persistent
private long groupid;

/** Indicated the time of the last login */
@Persistent
private Date lastlogin;

/** Indicated the time of the previous last login */
@Persistent
private Date prevlastlogin;

/** Map of user defined attributes (email, contact #, etc) */
//@Persistent(serialized = true)
//private Map String,String attributes = new HashMap
String,String ( );

/** Map of custom dashboard query settings */
//@Persistent(serialized = true)
//private Map String,String parameters = new HashMap
String,String ( );




/**
 * CONSTRUCTOR - creates a new User object with the specified full
name,
 * user-id, and password.
 *
 * @param name (String) full user name
 * @param user (String) user id - used for authentication
 * @param pwd (String) password - used for authentication
 */
public User ( String name, String user, String pwd )
{
this.fullName = name;
this.userName = user;
this.password = pwd;
}




/**
 * Gets the Unique Identifier for this object.
 *
 * @return (long) unique id
 */
public long getID ( )
{
return id;
}

/**
 * Sets the Unique Identifier for this object.
 *
 * @param id (long) unique id
 */
public void setID ( long id )
{
this.id = id;
}

/**
 * Returns the full name of the user.
 *
 * @return (String) full user name
 */
public String getFullName ( )
{
return fullName;
}

/**
 * Sets the full name of the user.
 *
 * @param name (String) full user name
 */
public void setFullName ( String name )
{
this.fullName = name;
}

/**
 * Returns the user-id of the user.  This is used for
 * authentication.
 *
 * @return (String) user-id
 */
public String getUserID ( )
{
return userName;
}

/**
 * Sets the user-id of the user.  This is used for
 * authentication.
 *
 * @param id (String) user-id
 */
public void setUserID ( String id )
{
this.userName = id;
}

/**
 * Returns the password for this user.  This is used for
 * authentication.
 *
 * @return (String) password
 */
public String getPassword ( )
{
return this.password;
}

/**
 * Sets the password for this user.  This is used for
 * authentication.
 *
 * @return (String) password
 */
public void setPassword ( String pwd )
{
this.password = pwd;
}

/**
 * Returns the time of the last login.
 *
 * @return (Date) date
 */
public Date getLastLogin ( )
{
return lastlogin;
}

/**
 * Sets the time of the last login.
 *
 * @return (Date) date
 */
public void setLastLogin ( Date date )
{
this.lastlogin = date;
}

/**
 * Returns the time of the previous last login.
 *
 * @return (Date) date
 */
public Date getPreviousLastLogin ( )
{
return prevlastlogin;
}

/**
 * Sets the time of the previous last login.
 *
 * @return (Date) date
 */
public void setPreviousLastLogin ( Date date )
{
this.prevlastlogin = date;
}

/**
 * Returns the account-id this user is associated with.
 *
 * @return (Long) owning account-id
 */
public Long getOwningAccount ( )
{
return accountid;
}

/**
 * Sets the account-id this user is associated with.
 *
 

[appengine-java] Failure to write objects to HttpSession - NotSerializableException : LazyResult

2010-06-02 Thread Shawn Draper
I am storing user-profile information in the data store and retrieving
with the following code:

public static User getUserByID ( String userName ) throws Exception
{
PersistenceManager mgr = PMF.getInstance
( ).getPersistenceManager ( );
Query query = mgr.newQuery ( User.class );
query.setFilter ( userName == param );
query.declareParameters ( String param );

try
{
List User results = (List User) query.execute
( userName );
Iterator User i = results.iterator ( );
if ( i.hasNext ( ) )
return mgr.detachCopy ( i.next ( ) );
else
throw new Exception ( Unable to locate user [ +
userName + ] );
}
finally
{
query.closeAll ( );
mgr.close ( );
}
}

I'm storing the data in the HttpSession object with the following
code:

req.getSession ( true ).setAttribute ( USER, user );
log ( Session data loaded.  Redirecting to  + nxtactn + ... );
resp.sendRedirect ( nxtactn );

The following Exception is thrown when the Servlet redirects.

/Login
java.lang.RuntimeException: java.io.NotSerializableException:
org.datanucleus.store.appengine.query.LazyResult
at
com.google.apphosting.runtime.jetty.SessionManager.serialize(SessionManager.java:
361)
at
com.google.apphosting.runtime.jetty.SessionManager.createEntityForSession(SessionManager.java:
341)
at com.google.apphosting.runtime.jetty.SessionManager
$AppEngineSession.save(SessionManager.java:162)
at
com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:
41)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1157)
at
com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:
43)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1157)
at
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:
388)
at
org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:
216)
at
org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:
182)
at
org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:
765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:
418)
at
com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:
238)
at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:
152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:
542)
at org.mortbay.jetty.HttpConnection
$RequestHandler.headerComplete(HttpConnection.java:923)
at
com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:
76)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at
com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:
135)
at
com.google.apphosting.runtime.JavaRuntime.handleRequest(JavaRuntime.java:
250)
at com.google.apphosting.base.RuntimePb$EvaluationRuntime
$6.handleBlockingRequest(RuntimePb.java:5838)
at com.google.apphosting.base.RuntimePb$EvaluationRuntime
$6.handleBlockingRequest(RuntimePb.java:5836)
at
com.google.net.rpc.impl.BlockingApplicationHandler.handleRequest(BlockingApplicationHandler.java:
24)
at com.google.net.rpc.impl.RpcUtil.runRpcInApplication(RpcUtil.java:
398)
at com.google.net.rpc.impl.Server$2.run(Server.java:852)
at
com.google.tracing.LocalTraceSpanRunnable.run(LocalTraceSpanRunnable.java:
56)
at
com.google.tracing.LocalTraceSpanBuilder.internalContinueSpan(LocalTraceSpanBuilder.java:
576)
at com.google.net.rpc.impl.Server.startRpc(Server.java:807)
at com.google.net.rpc.impl.Server.processRequest(Server.java:369)
at
com.google.net.rpc.impl.ServerConnection.messageReceived(ServerConnection.java:
442)
at
com.google.net.rpc.impl.RpcConnection.parseMessages(RpcConnection.java:
319)
at
com.google.net.rpc.impl.RpcConnection.dataReceived(RpcConnection.java:
290)
at com.google.net.async.Connection.handleReadEvent(Connection.java:
474)
at
com.google.net.async.EventDispatcher.processNetworkEvents(EventDispatcher.java:
831)
at
com.google.net.async.EventDispatcher.internalLoop(EventDispatcher.java:
207)
at com.google.net.async.EventDispatcher.loop(EventDispatcher.java:
103)
at
com.google.net.rpc.RpcService.runUntilServerShutdown(RpcService.java:
251)
at com.google.apphosting.runtime.JavaRuntime
$RpcRunnable.run(JavaRuntime.java:413)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.NotSerializableException:
org.datanucleus.store.appengine.query.LazyResult