• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ORM Entities in Session

 
syed aliarshad
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are the best practices of putting objects in session?
What should be the nature of those objects?
Can ORM entities be used in session or is it a bad practice?

We are using Toplink entities in session. They are working fine in non clustered environment. But when we take them to clustered environment and test the fail over scenario then we are having problems.

Thanks in advance
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once outside of a transaction your entities are detached and are just regular POJO's. I doubt this is a problem so much with ORM but rather your cluster is managing its sessions, or how you are re-attaching your entities. Remember that serializing objects that are currently in a PersistenceContext/Cache will also cause them to detach.

 
syed aliarshad
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Cluster is managing its session perfectly but throws null pointer exception on below given line: Note: All other properties in the class are working fine except for this toplink related property.

---------------------------------------

private ValueHolderInterface admin= new ValueHolder();
public Admin getAdmin() {
return (Admin)admin.getValue();
}
--------------------------------------

You may be right. Once its outside of the transaction, it is a simple POJO. We have cache server, using JMS cache implementation with JMS Coordinated Cache.
So after failing over, how can we re-attach the object?

Thanks for the reply.
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well what are you trying to do? If you are just trying to access information on the detached entity you should be able to assuming that you made sure that what ever you are trying to access was loaded before it became detached (Some things are lazy loaded so you have to trigger this). Now if you are needing to re-attach this entity so its state can be written to the database, inside of a transaction you would call



Above is the JPA way, I have not used Toplink so if you are not using JPA you will have to find the Toplink equivalent.
 
syed aliarshad
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have a clustered environment with 2 tomcat nodes. We are in the testing phase. When we test the fail over scenario then the load balancer sends request to other alive server but on the that alive server, system throws null pointer exception for ValueHolderInterface property.

I guess, as you describe that after serialization, ORM entity gets detached. So may be I need to load object with all dependent object on the alive server.???

thanks
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Serialization of lazy (value holder) relationships that have not been instantiated will not serialize the value, so if you cannot access the value after serialization.

You could look-up the object in a local session to get a live instances. i.e. call session.readObject(object), or in JPA em.find(class, id).
If you have changes in the object, then you will need to merge these into a new managed instance.

You could also force instantiation of all of the required object's relationship before serialization.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic