-->
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: Initialize proxy - no Session on an string variables
PostPosted: Mon Mar 10, 2008 9:01 pm 
Beginner
Beginner

Joined: Wed Mar 05, 2008 10:32 am
Posts: 48
On server start and on session "timeout", i'm getting the .LazyInitializationException: could not initialize proxy - no Session error.

Looking at the jsp code, it appears on the 4th line of the following code.
Code:
VenueEnt venue = new VenueEnt();
venue = (VenueEnt)request.getAttribute("venue");
session.setAttribute("venue", venue);
address = venue.getAddress() + "," + venue.getZip();


but those objects are strings.

before this jsp code is called, a servlet is called and this is all that is happening.
Code:
Long venueId = Long.parseLong(request.getParameter("venueId"));
VenueEnt venue = new VenueDao().findById(venueId, false);
      
request.setAttribute("venue", venue);


and then forwarding to the jsp.

Why is this happening?

Here is my class
Code:
@Entity
@TableGenerator(name="ids_generator", table="IDS")
public class VenueEnt {
...
   /** The address. */
   private String address;
   
   /** The city. */
   private String city;
   
   /** The state. */
   private String state;
   
   /** The zip. */
   private String zip;

...

   /**
    * Gets the address.
    *
    * @return the address
    */
   @Column(nullable = false, length = 150)
   public String getAddress() {
      return address;
   }

   /**
    * Sets the address.
    *
    * @param address the address to set
    */
   public void setAddress(String address) {
      this.address = address;
   }

   /**
    * Gets the city.
    *
    * @return the city
    */
   @Column(nullable = false, length = 50)
   public String getCity() {
      return city;
   }

   /**
    * Sets the city.
    *
    * @param city the city to set
    */
   public void setCity(String city) {
      this.city = city;
   }

   /**
    * Gets the state.
    *
    * @return the state
    */
   @Column(nullable = false, length = 2)
   public String getState() {
      return state;
   }

   /**
    * Sets the state.
    *
    * @param state the state to set
    */
   public void setState(String state) {
      this.state = state;
   }

   /**
    * Gets the zip.
    *
    * @return the zip
    */
   @Column(nullable = false, length = 5)
   public String getZip() {
      return zip;
   }

   /**
    * Sets the zip.
    *
    * @param zip the zip to set
    */
   public void setZip(String zip) {
      this.zip = zip;
   }

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 16, 2008 3:26 pm 
Beginner
Beginner

Joined: Wed Mar 05, 2008 10:32 am
Posts: 48
So i still have not found a solution and noticed the same thing occurs no matter what object i'm trying to access from the class (not just address).

Continuing developement i have noticed another message appearing on server startup and think this might be related. Please advise.
Using
15:14:06,773 INFO Environment:514 - Hibernate 3.2.4.sp1
15:14:06,788 INFO Environment:547 - hibernate.properties not found
15:14:06,788 INFO Environment:681 - Bytecode provider name : cglib
15:14:06,804 INFO Environment:598 - using JDK 1.4 java.sql.Timestamp handling
15:14:06,960 INFO Version:15 - Hibernate Annotations 3.3.0.GA
15:14:06,991 INFO Configuration:1426 - configuring from resource: /hibernate.cfg.xml
15:14:06,991 INFO Configuration:1403 - Configuration resource: /hibernate.cfg.xml
15:14:07,210 INFO Configuration:1541 - Configured SessionFactory: null


Code:
INFO: Starting Servlet Engine: Apache Tomcat/6.0.13
Mar 16, 2008 3:14:06 PM org.apache.catalina.session.StandardManager doLoad
SEVERE: IOException while loading persisted sessions: java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: com.epixentertainment.model.VenueEnt
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: com.epixentertainment.model.VenueEnt
   at java.io.ObjectInputStream.readObject0(Unknown Source)
   at java.io.ObjectInputStream.readObject(Unknown Source)
   at org.apache.catalina.session.StandardSession.readObject(StandardSession.java:1439)
   at org.apache.catalina.session.StandardSession.readObjectData(StandardSession.java:942)
   at org.apache.catalina.session.StandardManager.doLoad(StandardManager.java:394)
   at org.apache.catalina.session.StandardManager.load(StandardManager.java:321)
   at org.apache.catalina.session.StandardManager.start(StandardManager.java:637)
   at org.apache.catalina.core.ContainerBase.setManager(ContainerBase.java:438)
   at org.apache.catalina.core.StandardContext.start(StandardContext.java:4255)
   at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
   at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
   at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
   at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
   at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
   at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
   at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
   at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
   at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
   at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
   at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
   at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
   at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
   at org.apache.catalina.core.StandardService.start(StandardService.java:516)
   at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
   at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
   at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: java.io.NotSerializableException: com.epixentertainment.model.VenueEnt
   at java.io.ObjectOutputStream.writeObject0(Unknown Source)
   at java.io.ObjectOutputStream.writeObject(Unknown Source)
   at org.apache.catalina.session.StandardSession.writeObject(StandardSession.java:1515)
   at org.apache.catalina.session.StandardSession.writeObjectData(StandardSession.java:959)
   at org.apache.catalina.session.StandardManager.doUnload(StandardManager.java:517)
   at org.apache.catalina.session.StandardManager.unload(StandardManager.java:463)
   at org.apache.catalina.session.StandardManager.stop(StandardManager.java:667)
   at org.apache.catalina.core.StandardContext.stop(StandardContext.java:4496)
   at org.apache.catalina.core.ContainerBase.removeChild(ContainerBase.java:924)
   at org.apache.catalina.startup.HostConfig.undeployApps(HostConfig.java:1180)
   at org.apache.catalina.startup.HostConfig.stop(HostConfig.java:1151)
   at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:313)
   at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
   at org.apache.catalina.core.ContainerBase.stop(ContainerBase.java:1086)
   at org.apache.catalina.core.ContainerBase.stop(ContainerBase.java:1098)
   at org.apache.catalina.core.StandardEngine.stop(StandardEngine.java:448)
   at org.apache.catalina.core.StandardService.stop(StandardService.java:584)
   at org.apache.catalina.core.StandardServer.stop(StandardServer.java:744)
   at org.apache.catalina.startup.Catalina.stop(Catalina.java:616)
   at org.apache.catalina.startup.Catalina.start(Catalina.java:591)
   ... 6 more
Mar 16, 2008 3:14:06 PM org.apache.catalina.session.StandardManager start
SEVERE: Exception loading sessions from persistent storage


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 17, 2008 3:15 am 
Senior
Senior

Joined: Tue Jul 25, 2006 9:05 am
Posts: 163
Location: Stuttgart/Karlsruhe, Germany
Hi,

In response to your 2nd post, can you just make VenueEnt implement Serializable ?

Cheers,

Andy

_________________
Rules are only there to be broken


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 17, 2008 10:45 am 
Beginner
Beginner

Joined: Wed Mar 05, 2008 10:32 am
Posts: 48
I remember trying this but getting an error about a serial version id not being equal. I reverted back wanted to solve the initial problem first but since i'm thinking these are related i will play around with the serialized classes.
I will attempt to replicate the error since initially i did not get it.

Is it good practice to make all my entities serializable?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 17, 2008 4:14 pm 
Beginner
Beginner

Joined: Wed Mar 05, 2008 10:32 am
Posts: 48
So after further testing i dont think these are related.
Somehow i fixed it but i was playing around with request and session attributes.
Somehow when i set the request attribute on the servlet level, it was null when retrieving.

If anyone has any comment or know of an explination let me know.. also that serializable question still remains.

Quote:
Is it good practice to make all my object model classes serializable?

[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 18, 2008 3:50 am 
Senior
Senior

Joined: Tue Jul 25, 2006 9:05 am
Posts: 163
Location: Stuttgart/Karlsruhe, Germany
Hi,

You don't have to implement Serializable (Hibernate does not require it), but if you are working with HttpSession(s) you are going to need it. It is also needed if you want to store and entity as a blob in the db, to do this the entity itself needs to serializable, along with all it's variables.

Cheers,

Andy

_________________
Rules are only there to be broken


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 18, 2008 11:30 am 
Beginner
Beginner

Joined: Wed Mar 05, 2008 10:32 am
Posts: 48
What about the pros and cons of making it serializable? Does it affect performance?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 20, 2008 8:08 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
What about the pros and cons of making it serializable? Does it affect performance?

No performance impact, only cons.

Code:
VenueEnt venue = new VenueEnt();
venue = (VenueEnt)request.getAttribute("venue");

the "new VenueEnt()" is useless, as you throw it away on the second row: that has a performance impact.

Code:
Long venueId = Long.parseLong(request.getParameter("venueId"));
VenueEnt venue = new VenueDao().findById(venueId, false);

I really think it could be better to have this code moved to the servlet, and avoiding entities as session variables; in that case you wouldn't need the entities Serializable.
So you actually dont' need it but yes it is a good practice to have them serializable.


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.