[CDBI] Class::DBI and Apache::Session - Why does it work?

Brian Gorby gorbster at gmail.com
Fri Dec 2 21:31:36 GMT 2005

I'm trying to understand exactly how the following (simplified) scenario 
works in a mod_perl web application:

I've mapped a User table to a User entity class which subclasses 
Class::DBI::MySQL. In the web application, I define

$user = User->retrieve();

And then save $user in a session object, which is also stored in a MySQL 

%my_session{my_user} = $user;

I then restart both Apache and MySQL. The session is restored, and I 
pull back out $user

$user = %my_session{my_user};

I can then make any updates I wish to $user. But why? I thought all I 
persisted was a reference to some memory that would've gotten destroyed 
upon restarting of servers.

Now what's even more interesting is, if I then have a foreign key in 
$user, and I manually delete the row that's referenced by $user (so that 
$user logically no longer lives in the database), I can still access 
foreign key objects like $user->address(), and update them as I please - 
even upon successive server restarts.

Any insight as to why this works would be appreciated.



More information about the ClassDBI mailing list