You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by Les Hazlewood <lh...@apache.org> on 2011/01/04 19:10:01 UTC

Re: Storing sessins in an RDBMS instead of an enterprise cache?

Hi Brian,

I had planned on trying to help with this before the holidays, but
couldn't get around to it.  I'm back from vacation now and glad to try
and help.

Typically the attributes are serialized into a byte array and saved as
a blob column.  Hibernate has a 'blob' property type that can be
specified.  You can also specify convenience methods on your
SimpleSession subclass that only Hibernate would use:

public byte[] getAttributeBytes() {
    return serialize(getAttributes());
}

public void setAttributeBytes(byte[] bytes) {
    setAttributes(deserialize(bytes));
}

your 'serialize' and 'deserialize' methods above could delegate to an
org.apache.shiro.io.DefaultSerializer instance to make your life easy.

All of this could also be externalized into an
org.hibernate.usertype.UserType implementation as well, and then you
specify that UserType for the 'attributes' property.

A slightly more robust idea is to use the same UserType technique, but
instead of a byte array, serialize the map to a text output, e.g.
using YAML, JSON, or XML and save that in a large text (e.g. clob)
column.  This is better in case you (or a 3rd party) introduce any
backwards-incompatible binary serialization changes to anything that
is stored in the attribute map. Using text will help avoid that
problem since objects would be recreated via reflection instead of
binary deserialization - at the expense of the added size and
serialization time.

HTH!

Les

On Tue, Dec 21, 2010 at 10:45 AM, zooxmusic <br...@109forest.com> wrote:
>
> Hello?
> --
> View this message in context: http://shiro-user.582556.n2.nabble.com/Storing-sessins-in-an-RDBMS-instead-of-an-enterprise-cache-tp5645213p5855606.html
> Sent from the Shiro User mailing list archive at Nabble.com.
>