The Artima Developer Community
Sponsored Link

Java Answers Forum
problem with bean Entity BMP

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
virginie

Posts: 1
Nickname: vbuchin
Registered: Feb, 2003

problem with bean Entity BMP Posted: Feb 12, 2003 7:51 AM
Reply to this message Reply
Advertisement
I want to use Bean entity BMP but i have:<br>
Erreur consultation : java.rmi.ServerException: EJBException:; nested exception is: javax.ejb.EJBException: null; CausedByException is: null <br>
this error and I don't know where is the problem!<br>
Please Help me<br>
I have a problem with the context.getPrimaryKey(), and if i replace with a code wich is in database there is no problem!<br>

I give you my code<br>

package agrProd;
 
import java.rmi.RemoteException;
import java.sql.Connection;
import java.util.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
 
import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.FinderException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
 
<br>
public class PeriodiciteBean implements EntityBean {
	public EntityContext ctx;
 
	public Integer code;
	public String libe;
	public Integer nbjt;
	public Character vali;
	public String utim;
	public Date modi;
	
	public Integer getCODE_PERIODICITE() {return this.code;}
	public String getLIBE_PERIODICITE() {		return this.libe;}
	public Integer getNBJT_PERIODICITE() {
		return this.nbjt;
	}
	public Character getVALI_PERIODICITE() {
		return this.vali;
	}
	public String getUTIM_PERIODICITE() {
		return this.utim;
	}
	public Date getMODI_PERIODICITE() {
		return this.modi;
	}	
	public void setCODE_PERIODICITE(Integer code)	{
		this.code=code;
	}
public void setLIBE_PERIODICITE(String libe)	{
		this.libe=libe;
	}
	public void setNBJT_PERIODICITE(Integer nbjt)	{
		this.nbjt=nbjt;
	}
 
	public void setVALI_PERIODICITE(Character vali)	{
		this.vali=vali;
	}
 
	public  void setUTIM_PERIODICITE(String utim)	{
		this.utim=utim;
	}
 
	public  void setMODI_PERIODICITE(Date modi)	{
		this.modi=modi;
	}
 
 
public void ejbRemove() throws javax.ejb.RemoveException {
		System.out.println("PeriodiciteBean.ejbRemove(): begin");
Connection con = null;
try {con = getConnection();
PreparedStatement statemt =con.prepareStatement("DELETE FROM PERIODICITE WHERE CODE_PERIODICITE=?");
statemt.setInt(1, this.getCODE_PERIODICITE().intValue());
if (statemt.executeUpdate() != 1) {
throw new EJBException("Echec de la suppression");
}
statemt.close();
} catch (SQLException sqle) {
throw new EJBException(sqle);
} finally {
    try {if (con != null) 
      {con.close();}
} catch (SQLException sqle) {}
}
}
 
 
public void ejbStore() {
System.out.println("PeriodiciteBean.ejbStore(): begin");
Connection con = null;
try {
con = getConnection();
PreparedStatement statemt =con.prepareStatement(
"UPDATE PERIODICITE SET LIBE_PERIODICITE=?, NBJT_PERIODICITE=?, VALI_PERIODICITE=?, UTIM_PERIODICITE=?, MODI_PERIODICITE=? WHERE CODE_PERIODICITE=?");
statemt.setString(1, this.getLIBE_PERIODICITE());
statemt.setInt(2, this.getNBJT_PERIODICITE().intValue());
statemt.setString(3, this.getVALI_PERIODICITE().toString());
statemt.setString(4, this.getUTIM_PERIODICITE());
statemt.setDate(5, (java.sql.Date)this.getMODI_PERIODICITE());
statemt.setInt(6, this.getCODE_PERIODICITE().intValue());
if (statemt.executeUpdate() != 1) {
throw new EJBException("Echec de la sauvegarde");
}
statemt.close();
} catch (SQLException sqle) {
throw new EJBException(sqle);
} finally {
	try {
	if (con != null) {
	con.close();
	}
} catch (SQLException sqle) {
}
}
}
 
 
public EntityContext getEntityContext() {
       return ctx;
    }
 
public void ejbLoad() {
 code = ((Integer) ctx.getPrimaryKey()).intValue();
 Connection con = null;
	try {
	con = getConnection();
	PreparedStatement statemt =
	con.prepareStatement("SELECT CODE_PERIODICITE,LIBE_PERIODICITE,NBJT_PERIODICITE,VALI_PERIODICITE,UTIM_PERIODICITE,MODI_PERIODICITE FROM PERIODICITE WHERE CODE_PERIODICITE=?");
statemt.setInt(1, code);
ResultSet rs = statemt.executeQuery();
if (!rs.next()) {
throw new EJBException("Object pas trouv?");
}
this.setCODE_PERIODICITE(code);
this.setLIBE_PERIODICITE(rs.getString(2));
this.setNBJT_PERIODICITE(rs.getInt(3));
this.setVALI_PERIODICITE(new Character(rs.getString(4).charAt(0)));
this.setUTIM_PERIODICITE(rs.getString(5));		this.setMODI_PERIODICITE(rs.getDate(6));
	rs.close();
	statemt.close();
	} catch (SQLException sqle) {
	throw new EJBException(sqle);
	}
	finally {
		try {
			if (con != null) {
				con.close();
			}
		} catch (SQLException sqle) {
		}
	}
	
	
 public PeriodiciteBean()
  {
    // constructor
  }
public Integer ejbCreate()throws CreateException {return code;}
 
 
public Integer ejbCreate(PeriodiciteDetails perio) throws CreateException {
System.out.println("PeriodiciteBean.ejbCreazte(): begin");
this.code=perio.getCODE_PERIODICITE();
this.libe=perio.getLIBE_PERIODICITE();
this.nbjt=perio.getNBJT_PERIODICITE();
this.vali=perio.getVALI_PERIODICITE();
this.utim=perio.getUTIM_PERIODICITE();
this.modi=perio.getMODI_PERIODICITE();
Connection con = null;
try {
con = getConnection();
PreparedStatement statemt =con.prepareStatement(
"INSERT INTO PERIODICITE VALUES(?,?,?,?,?,?)");
statemt.setInt(1, perio.getCODE_PERIODICITE().intValue());
statemt.setString(2, perio.getLIBE_PERIODICITE());
statemt.setInt(3, perio.getNBJT_PERIODICITE().intValue());
statemt.setObject(4, perio.getVALI_PERIODICITE());
statemt.setString(5, perio.getUTIM_PERIODICITE());
statemt.setObject(6, perio.getMODI_PERIODICITE());
if (statemt.executeUpdate() != 1) {
throw new CreateException("Echec de la cr?ation d'un Utilisateur");
}
} 
catch (SQLException sqle) {
}
finally {
	try {
	if (con != null) {
	con.close();
	}
	}
catch (SQLException sqle) {
}
}
return perio.getCODE_PERIODICITE();
}
 
 
private Connection getConnection() {
System.out.println("PeriodiciteBean.getConnection: begin");
try {
Context ctx = new InitialContext();
DataSource db = (DataSource) ctx.lookup("java:/OracleDS");
return db.getConnection();
} catch (NamingException ne) {
ne.printStackTrace();
throw new EJBException(ne);
} catch (java.sql.SQLException sqle) {
sqle.printStackTrace();
throw new EJBException(sqle);
}
}
 
public void ejbPostCreate(PeriodiciteDetails perio)
throws CreateException {
System.out.println("PeriodiciteBean.PostCreate begin");
}
public void ejbPostCreate()
	throws CreateException {
}
 
public Integer ejbFindByPrimaryKey(Integer code) throws FinderException {
System.out.println("PeriodiciteBean.ejbFindByPrymariKey(): begin");
PeriodiciteDetails perio=null;
try {
Connection connection = getConnection();
PreparedStatement statement =
connection.prepareStatement(
"SELECT * FROM PERIODICITE WHERE CODE_PERIODICITE = ?");
statement.setInt(1, code.intValue());
ResultSet resultSet = statement.executeQuery();
if (!resultSet.next()) {
statement.close();
connection.close();
throw new FinderException("Could not find: " + code);
}
statement.close();
connection.close();
return code;
} catch (SQLException e) {
throw new EJBException("Could not find: " + code, e);
}
}
 
 
public Collection ejbFindAllPeriodicites(String critere, String ordre) throws FinderException {
System.out.println("PeriodiciteBean.ejbFindAll(): begin");
ArrayList periodicites = new ArrayList();
Connection con = null;
try {
	con = getConnection();
	PreparedStatement statement;
	if (ordre.compareTo("0") == 0) {
	statement =
	con.prepareStatement(
"SELECT * FROM PERIODICITE ORDER BY " + critere + "");
} else {
statement =con.prepareStatement("SELECT * FROM PERIODICITE ORDER BY "+ critere+ " DESC");
}
ResultSet resultSet = statement.executeQuery();
while (resultSet.next()) {
periodicites.add(new PeriodiciteDetails(resultSet));
}
return (Collection) periodicites;
} catch (SQLException sqle) {
throw new EJBException(sqle);
} finally {
	try {
	if (con != null) {
	con.close();
	}
} catch (Exception e) {
}
}
}
 
 
public void setEntityContext(EntityContext ctx) {
this.ctx = ctx;
}
public void unsetEntityContext() {
this.ctx=null;
}
public void ejbActivate() {
 
}
public void ejbPassivate() {
}
}
 
<br>
and it is my session<br>
<br>
public class GestionPeriodiciteBean implements SessionBean {
	private SessionContext ctx;
public void ajoutPeriodicite(PeriodiciteDetails nouvellePeriodicite)
throws CreateException {			
PeriodiciteLocalHome home;
home = this.getPeriodiciteLocalHome();
home.create(nouvellePeriodicite);
}
<br>
public PeriodiciteDetails getPeriodicite(Integer code)
throws FinderException {
PeriodiciteLocalHome home;
home = this.getPeriodiciteLocalHome();
return null;
}
<br>
public java.util.Collection listePeriodicite(String critere,String ordre)
throws FinderException {
System.out.println("GestionBean.setEntity begin");
java.util.ArrayList periodicites = new java.util.ArrayList();
PeriodiciteLocalHome home;
home = this.getPeriodiciteLocalHome();
for (java.util.Iterator it = home.findAllPeriodicites(critere,ordre).iterator();
it.hasNext();
) {
PeriodiciteLocal periodicite = (PeriodiciteLocal) it.next();
periodicites.add(
new PeriodiciteDetails(
periodicite.getCODE_PERIODICITE(),
periodicite.getLIBE_PERIODICITE(),
periodicite.getNBJT_PERIODICITE(),
periodicite.getVALI_PERIODICITE(),
periodicite.getUTIM_PERIODICITE(),
periodicite.getMODI_PERIODICITE()));
}
return (java.util.Collection) periodicites;
}
<br>
public PeriodiciteLocalHome getPeriodiciteLocalHome() {
System.out.println("GestionBean.setEntity begin");
PeriodiciteLocalHome home;
try {
	InitialContext ic = new InitialContext();
	Object obj = ic.lookup("java:comp/env/agrProd/Periodicite");
return (PeriodiciteLocalHome) PortableRemoteObject.narrow(
obj,
PeriodiciteLocalHome.class);
}
catch (javax.naming.NamingException e) {
throw new EJBException();
}
}<br>
public void ejbCreate() {}
public void ejbPostCreate() {}
public void ejbRemove() {}
public void ejbActivate() {}
public void ejbPassivate() {}
public void setSessionContext(SessionContext ctx) {
	this.ctx = ctx;}
 
}
 
 
 

Topic: Jini-funktionality via external Java-machine Previous Topic   Next Topic Topic: please help me with this interface.

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use