[jboss-user] [JBossCache] - Re: PojoCache can't find classloader
chip_schoch
do-not-reply at jboss.com
Sat Mar 10 12:44:49 EST 2007
Thanks for all your help. After multiple readings of the docs I am starting to get it. I now have the pojo caching somewhat working, however it appears only to serialize my object rather than pojo cache it.
I verified that the object inserted in one instance of JBoss is retrieved by the other but no field level changes are propagated.
When I removed the implements Serializable from the PojoCacheable object I got an exception:
2007-03-10 17:28:13,876 WARN [org.jboss.cache.TreeCache] putObject(): exception occurred: java.lang.IllegalArgumentException: PojoCache.putObject(): Object type is neither aspectized nor Serializable nor an array of primitives. Object class name is com.eLynx.Dispatch.SessionData
According to the documentation I should not have to aopc the objects when using jdk 5.0? Is that correct? I should just annotate it and get the aspectization at loadtime?
The code for the object is:
package com.eLynx.Dispatch;
|
| import java.io.Serializable;
|
| import com.eLynx.Database.ConnectionManager;
| import com.eLynx.Database.Entity.Customer;
| import com.eLynx.Database.Entity.UserInstance;
|
| import com.eLynx.Definition.CriteriaConstants;
| import com.eLynx.Definition.ParameterConstants;
|
| import com.eLynx.logging.Loggable;
|
| import org.hibernate.Criteria;
| import org.hibernate.Session;
|
| import org.hibernate.criterion.Expression;
|
| /**
| * Class SessionData
| */
|
| @org.jboss.cache.aop.annotation.PojoCacheable
| public class SessionData extends SessionDataInterface implements Loggable, Serializable
| {
| @org.jboss.cache.aop.annotation.Serializable
| UserInstance m_user = null;
| @org.jboss.cache.aop.annotation.Serializable
| Customer m_customer = null;
| String m_customerId = "1"; // default to system id
|
| /**
| * Constructor: SessionData
| *
| */
|
| public SessionData ()
| {
| }
|
| /**
| * Method: getCustomer<BR>
| * Return the current customer. If it is null try to look it up through the user.
| *
| *
| * @return
| *
| * @throws Exception
| */
|
| public Customer getCustomer () throws Exception
| {
| if (m_customer == null)
| {
| if (m_user != null)
| {
| Session session = ConnectionManager.getSession ();
| Criteria crit =
| session.createCriteria (Customer.class).add (Expression.eq (CriteriaConstants.COL_OBJECTID,
| m_user.getCustomerId ()));
| setCustomer ((Customer) crit.uniqueResult ());
| }
| }
| return m_customer;
| }
|
| /**
| * Method: getCustomerId
| *
| *
| * @return
| *
| * @throws Exception
| */
|
| public String getCustomerId () throws Exception
| {
| return m_customerId;
| }
|
| /**
| * Method: getOfficeId
| *
| *
| * @return
| */
|
| String getOfficeId ()
| {
| if (m_user == null)
| return "0"; // Default office
| else return Integer.toString (getUser ().getOfficeId ());
| }
|
| /**
| * Method: getUser
| *
| *
| * @return
| */
|
| public UserInstance getUser ()
| {
| return m_user;
| }
|
| /**
| * Method: initialize
| *
| *
| * @param arg
| */
|
| @Override public void initialize (String... arg)
| {
| }
|
| /**
| * Method: isActive
| *
| *
| * @return
| */
|
| public boolean isActive ()
| {
| boolean result = false;
| if (m_user != null)
| result = m_user.getActiveFlag () == ParameterConstants.YES_C;
| return result;
| }
|
| /**
| * Method: render
| *
| *
| * @return
| */
|
| public String render ()
| {
| StringBuffer buffer = new StringBuffer (256);
| buffer.append (super.render ());
| buffer.append (String.format (" %20s = %d\n", "User Id:",
| (m_user == null) ? 0 : m_user.getObjectId ()));
| buffer.append (String.format (" %20s = %s\n", "Customerer Id:", m_customerId));
| return buffer.toString ();
| }
|
| /**
| * Method: setCustomer
| *
| *
| * @param customer
| */
|
| public void setCustomer (Customer customer)
| {
| if (customer != null)
| setCustomerId (customer.getObjectId ());
|
| m_customer = customer;
| }
|
| /**
| * Method: setCustomerId
| *
| *
| * @param customerId
| */
|
| public void setCustomerId (int customerId)
| {
| m_customerId = Integer.toString (customerId);
| }
|
| /**
| * Method: setCustomerId
| *
| *
| * @param customerId
| */
|
| public void setCustomerId (String customerId)
| {
| m_customerId = customerId;
| }
|
| /**
| * Method: setUser
| *
| *
| * @param user
| */
|
| public void setUser (UserInstance user)
| {
| m_user = user;
| }
| }
|
The super class code is:
| package com.eLynx.Dispatch;
|
|
|
| import com.eLynx.Context.RequestContext;
| import com.eLynx.Database.ConnectionManager;
|
| import com.eLynx.Definition.ParameterConstants;
| import com.eLynx.Exception.ErrorMessage;
|
| import com.eLynx.logging.Loggable;
|
| import java.io.Serializable;
| import java.net.InetAddress;
|
| import java.util.HashMap;
| import java.util.Iterator;
|
| import java.util.Map.Entry;
|
| import org.apache.log4j.Logger;
|
| import org.hibernate.Session;
|
| /**
| * Interface SessionDataInterface
| */
|
| @org.jboss.cache.aop.annotation.InstanceOfPojoCacheable
| public abstract class SessionDataInterface implements Loggable, Serializable
| {
| static Logger logger = Logger.getLogger (SessionDataInterface.class);
| //
| boolean m_loggedIn = false;
| boolean m_active = false;
| String m_requestURL = "";
| HashMap<String, String> m_sessionValues = new HashMap<String, String> ();
|
| /**
| * Method: isAuthenticated<BR>
| * Checks the session for a session data and if one is found checks if the session is logged in.
| * If there is no current session data then it returns false.
| *
| *
| * @param request
| *
| * @return
| */
|
| public static boolean isAuthenticated (RequestContext context)
| {
| boolean result = false;
|
| SessionDataInterface obj = (SessionDataInterface) context.getSessionData ();
|
| if (obj != null)
| result = obj.getLoggedIn ();
| else
| logger.debug ("No session data object found");
|
| logger.debug ("isAuthenticated: " + result);
|
| return result;
| }
|
| /**
| * Method: getCustomerId
| *
| *
| * @return
| *
| * @throws Exception
| */
|
| public String getCustomerId () throws Exception
| {
| return getSessionValue (ParameterConstants.CUSTOMERID_PARM);
| }
|
| /**
| * Method: getDBSession
| *
| *
| * @return
| *
| * @throws Exception
| */
|
| public Session getDBSession () throws Exception
| {
| return ConnectionManager.getSession ();
| }
|
| /**
| * Method: getRequestURL
| *
| *
| * @return
| */
|
| public String getRequestURL ()
| {
| return m_requestURL;
| }
|
| /**
| * Method: getSessionValue
| *
| *
| * @param key
| *
| * @return
| */
|
| public String getSessionValue (String key)
| {
| String result = "";
| if (m_sessionValues.containsKey (key))
| result = m_sessionValues.get (key);
| return result;
| }
|
| /**
| * Method: getUserId
| *
| *
| * @return
| *
| * @throws Exception
| */
|
| public String getUserId () throws Exception
| {
| return getSessionValue (ParameterConstants.USERID_PARM);
| }
|
| /**
| * Method: initialize
| *
| *
| * @param arg
| *
| * @throws ErrorMessage
| * @throws Exception
| */
|
| public abstract void initialize (String... arg) throws Exception, ErrorMessage;
|
| /**
| * Method: isActive
| *
| *
| * @return
| */
|
| public boolean getActive ()
| {
| return m_active;
| }
|
|
| public boolean getLoggedIn ()
| {
| return m_loggedIn;
| }
|
| /**
| * Method: putSessionValue
| *
| *
| * @param key
| * @param value
| *
| * @return
| */
|
| public String putSessionValue (String key,
| String value)
| {
| return m_sessionValues.put (key, value);
| }
|
| /**
| * Method: render<br>
| * Dump the contents of the sessiondata map.
| *
| *
| * @return
| */
|
| public String render ()
| {
| StringBuffer buffer = new StringBuffer (256);
|
| try
| {
| InetAddress inetAddress = InetAddress.getLocalHost ();
| String hostName = inetAddress.getHostName ();
| buffer.append ("\n\n ************** Dumping SessionData contents *************\n");
| buffer.append (String.format (" %20s = %s\n", "hostname", hostName));
| buffer.append (String.format (" %20s = %s\n", "Logged In:", m_loggedIn ? "yes" : "no"));
| Iterator<Entry<String, String>> i = m_sessionValues.entrySet ().iterator ();
|
| while (i.hasNext ())
| {
| Entry<String, String> e = i.next ();
| buffer.append (String.format (" %20s = %s\n", e.getKey (), e.getValue ()));
| }
| }
| catch (Exception e)
| {
| buffer.append (e.getMessage ());
| }
|
| return buffer.toString ();
| }
|
| /**
| * Method: setActive
| *
| *
| * @param flag
| */
|
| public void setActive (boolean flag)
| {
| m_active = flag;
| }
|
| /**
| * Method: setCustomerId
| *
| *
| * @param id
| */
|
| public void setCustomerId (int id)
| {
| putSessionValue (ParameterConstants.CUSTOMERID_PARM, Integer.toString (id));
| }
|
| /**
| * Method: setCustomerId
| *
| *
| * @param id
| */
|
| public void setCustomerId (String id)
| {
| putSessionValue (ParameterConstants.CUSTOMERID_PARM, id);
| }
|
| /**
| * Method: setLoggedIn
| *
| *
| * @param flag
| */
|
| public void setLoggedIn (boolean flag)
| {
| logger.debug("Setting logged in: " + flag);
| m_loggedIn = flag;
| }
|
| /**
| * Method: setUserId
| *
| *
| * @param id
| */
|
| public void setUserId (int id)
| {
| putSessionValue (ParameterConstants.USERID_PARM, Integer.toString (id));
| }
|
| /**
| * Method: setCustomerId
| *
| *
| * @param id
| */
|
| public void setUserId (String id)
| {
| putSessionValue (ParameterConstants.USERID_PARM, id);
| }
| }
|
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4026884#4026884
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4026884
More information about the jboss-user
mailing list