-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: Getter & Setter for Tomcat sessions on Postgresql
PostPosted: Mon Feb 13, 2006 10:37 am 
Beginner
Beginner

Joined: Wed May 18, 2005 9:48 am
Posts: 31
Hi all,

I improved my application adding Database user management in order to have a Cluster. The problem is that one field ("session_data") must be bytea and I donĀ“t know how to make the setter & getter class and of course how to manage data from this field.

I tried everything, using Object type, httpSession type and no result. For example, i want to extract from each session an attribute that I had set, but this is inside session_data field.

Any ideas?.

Other thing is that when I stop tomcat server, sessions are still in database, so when you restart server, tomcat connector try to restore sessions in hibernate; problem? SessionFactory ID has changed and no name are avalaible (In tomcat 5.5.9 I had tried using JDBC Datasource that is in your hibernate PDF for tomcat and for me.. or i am so stupid it doesn't work).

Thanks all.


Top
 Profile  
 
 Post subject: Re: Getter & Setter for Tomcat sessions on Postgresql
PostPosted: Wed Feb 15, 2006 4:31 am 
Beginner
Beginner

Joined: Mon Jan 30, 2006 2:28 am
Posts: 47
Location: INDIA
Hi!
Please don't scold your self.
You Can.
Actually setter and getter method in a class is looking like

public class one{
String username;
String password;

public String getUsername(){
return username;
}
public void setUsername(String username){
this.username = username;
}

public String getPassword(){
return password;
}
public void setPassword(String password){
this.password= password;
}
}

If You are beginner in Hibernate, Pls try to refer the following link
http://www.laliluna.de/first-hibernate- ... orial.html

Thanks

_________________
A.Edward Durai
"The things which are impossible with men are possible with God."


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 15, 2006 7:03 am 
Beginner
Beginner

Joined: Wed May 18, 2005 9:48 am
Posts: 31
Hi,

thanks for your help, but I know this. I want to know how to manage bytea Postgresql field into a getter and Setter. I mean that ir you look at "session_data" table you could see that all session attributes are held into a bytea field.

My problem is that i want to extract those attributes in order to get their values. So that, i want to know how could I do table getter & setter for managing this field.

Thanks all.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 15, 2006 8:29 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
map it to byte array.

public void setMyBytes(byte [] value)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 16, 2006 7:29 am 
Beginner
Beginner

Joined: Wed May 18, 2005 9:48 am
Posts: 31
Thanks Baliuka, it works.

Now my problem is what do I have to do in order to convert this Byte array into the original tomcat's session data?.

I need this because Cluster use database table to make sessions persistents through all tomcat servers, and of course one of the session data Object is the hibernate's SessionFactory.

Any ideas?.

Thanks a lot.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 16, 2006 11:49 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
I am not sure I understand this problem, but if you need to desesialize this stuff the just read it from stream:
Object stuff = new ObjectInputStream(new ByteArrayInputStream(myBytes)).readObject();


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 17, 2006 8:01 am 
Beginner
Beginner

Joined: Wed May 18, 2005 9:48 am
Posts: 31
Ok i'll explain you:

First of all i have a table in postgresql called "tomcat_sessions" like this:

Code:
CREATE TABLE tomcat_sessions (
    id character varying(100) NOT NULL,
    "valid" character varying(1),
    max_inactive integer,
    last_access bigint,
    session_data bytea,
    app_name character varying
);
--
-- Definition for index tomcat_sessions_pkey (OID = 21012) :
--
ALTER TABLE ONLY tomcat_sessions
    ADD CONSTRAINT tomcat_sessions_pkey PRIMARY KEY (id);
COMMENT ON SCHEMA public IS 'Standard public schema';


Then, I let tomcat manage http sessions with this code into context.xml

Code:
.....
  <Manager
        className="org.apache.catalina.session.PersistentManager"
        debug="0"
        saveOnRestart="true"
        maxActiveSessions="-1"
        minIdleSwap="30"
        maxIdleSwap="600"
        maxIdleBackup="0">
        <Store className="org.apache.catalina.session.JDBCStore"
            driverName="org.postgresql.Driver"
            connectionURL="jdbc:postgresql://newintranet/intranet_fnac?user=sessionMGR"
            sessionTable="tomcat_sessions"
            sessionAppCol="app_name"
            sessionDataCol="session_data"
            sessionIdCol="id"
            sessionLastAccessedCol="last_access"
            sessionMaxInactiveCol="max_inactive"
            sessionValidCol="valid"
            debug="1" />
        </Manager>
.....


With this code tomcat inserts into postgresql table sessions that are created, update sessions that had changed its state and delete sessions when are invalidated.

Field, in which i am interested (session_data), is where tomcat insert session's attribute Objects, which is bytea type. And here is my necessity:

- You know now that session_data field is actually Http Session Attributes, so i want to make inversed process. I want to generate Object Data from field in order to extract data like this form: session.getAttribute("something");.

This method is implemented in order to make a Cluster, so each web application have their own Hibernate SessionFactory but Http sessions are shared between two, three, four servers. So if one of tomcat servers goes down, another one will get this session and this session user wouldn't be invalidated.

Thanks a lot.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 17, 2006 2:20 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
http://tomcat.apache.org/tomcat-5.5-doc ... howto.html


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.