# ejbPassivate



## mayer (22. Feb 2006)

Ich habe ein Stateful Session Bean. Dieses sieht folgendermaßen aus:


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

```
public abstract class ConnectionManagerBean implements javax.ejb.SessionBean {

	private Connection con = null;
	private String benutzerName = null;
	private String passwort = null;
	private boolean loggedIn = false;
	


public void ejbCreate(String benutzerName, String passwort){
	this.benutzerName = benutzerName;
	this.passwort = passwort;
}




public boolean doLogin(){ 
// do_Something
//...
}



public boolean doLogout(){ 
	try {
		con.close();
	}
	
	catch(SQLException e) {
		System.out.println("ERROR: Couldn't close Connection");
		e.printStackTrace();
		loggedIn = true;
		return false;
	}
	
	loggedIn = false;
	return true;
}




public Connection getConnection(){ 
 return this.con; 
}




public void ejbRemove(){ 
	
	try {
		con.close();
	}
	
	catch(SQLException e) {
		System.out.println("ERROR: Couldn't close Connection");
		e.printStackTrace();
		return;
	}
	
	this.benutzerName = null;
	this.passwort = null;
	this.loggedIn = false;
}



public void ejbCreate(){ 
}




public void ejbPassivate(){ 
}



}
```
---------------------------------------------------------------------------------------------------------------


*Meine Frage:
Was soll ich mit der ejbPassivate Methode machen?*

*Wenn ich nämlich nichts in ejbPassivate mache erhalte ich folgenden Fehler:*

---------------------------------------------------------------------------------------------------------------
19:29:32,078 WARN  [TransactionImpl] Transaction TransactionImpl:XidImpl[FormatI
d=257, GlobalId=MAYCOM/87, BranchQual=, localId=87] timed out. status=STATUS_ACT
IVE
19:36:21,515 WARN  [AbstractInstanceCache] failed to passivate, id=ejzz1evq-4
javax.ejb.EJBException: Could not passivate; failed to save state; CausedByExcep
tion is:
        oracle.jdbc.driver.OracleConnection
        at org.jboss.ejb.plugins.StatefulSessionFilePersistenceManager.passivate
Session(StatefulSessionFilePersistenceManager.java:404)
        at org.jboss.ejb.plugins.StatefulSessionInstanceCache.passivate(Stateful
SessionInstanceCache.java:93)
        at org.jboss.ejb.plugins.AbstractInstanceCache.tryToPassivate(AbstractIn
stanceCache.java:180)
        at org.jboss.ejb.plugins.LRUEnterpriseContextCachePolicy$OveragerTask.ru
n(LRUEnterpriseContextCachePolicy.java:419)
        at java.util.TimerThread.mainLoop(Timer.java:512)
        at java.util.TimerThread.run(Timer.java:462)
java.io.NotSerializableException: oracle.jdbc.driver.OracleConnection
        at java.ibjectOutputStream.writeObject0(ObjectOutputStream.java:1075)

        at java.ibjectOutputStream.defaultWriteFields(ObjectOutputStream.java
:1369)
        at java.ibjectOutputStream.writeSerialData(ObjectOutputStream.java:13
41)
        at java.ibjectOutputStream.writeOrdinaryObject(ObjectOutputStream.jav
a:1284)
        at java.ibjectOutputStream.writeObject0(ObjectOutputStream.java:1073)

        at java.ibjectOutputStream.writeObject(ObjectOutputStream.java:291)
        at org.jboss.ejb.plugins.StatefulSessionFilePersistenceManager.passivate
Session(StatefulSessionFilePersistenceManager.java:395)
        at org.jboss.ejb.plugins.StatefulSessionInstanceCache.passivate(Stateful
SessionInstanceCache.java:93)
        at org.jboss.ejb.plugins.AbstractInstanceCache.tryToPassivate(AbstractIn
stanceCache.java:180)
        at org.jboss.ejb.plugins.LRUEnterpriseContextCachePolicy$OveragerTask.ru
n(LRUEnterpriseContextCachePolicy.java:419)
        at java.util.TimerThread.mainLoop(Timer.java:512)
        at java.util.TimerThread.run(Timer.java:462)
---------------------------------------------------------------------------------------------------------------


Kann mir jemand helfen??

mfg manuel


----------



## clemson (22. Feb 2006)

probier das mal...



			
				Andreas Senft auf  [url=http://forum.springframework.org/archive/index.php/t-11475.html hat gesagt.:
			
		

> forum.springframework.org/archive/index.php/t-11475.html[/url]]I would guess that you need to null out your Hello instance in the passivate method. Otherwise the container will try to serialize it, which it cannot.



beziehungsweise

SessionBean#ejbPassivate()


----------



## Bleiglanz (24. Feb 2006)

jep, die Connection kann nicht "persistent" gemacht werden,

du musst sie in passivate zumachen, nullen und beim activate wieder öffnen (am besten die member-Varialbe gleich transient machen)


----------

