Win a copy of Head First Android this week in the Android forum!

Sven

Greenhorn
+ Follow
since Aug 31, 2004
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Sven

Hi
i whould like to convert my java bean into xml and then send it over a network to decode it en build my beans back

i know you can use XMLEncoder e = new XMLEncoder(
new BufferedOutputStream(
new FileOutputStream("Test.xml")))
but i wonderif there is a way to not save it as a file first and return a stream or a string in my function

like this :
public String getPaginaToXML() {
return "converted bean as xml"
}

thanx
thanx
I am using eclipse and Jboss
i hope i can manage to let the example run on those 2 i hava a litle experiance with struts so maibe i can do it

if anyone has a more simple example running on jboss maybe with an eclipse .project file to make sure i dont miss a spot it would be a great help
Does anybody know of a good one to many relations example with a test bean ore a test servlet.
am trying for over 2 weeks to get this thing to work but no luck
so if anybody knows of a good (running)example it would be a great help

and yes i have tryed google and many "good" tutorials but they never seem to work with me

ps a single bean works so its not the server nor db just i dont know how to add the one in the manny ore the many in the one
thanx
hi,
my first many to one test doesnt work
i get following error when i try to put something in my collection :
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: java.rmi.ServerException: RuntimeException; nested exception is:
java.lang.ClassCastException

here is the code from my client it works until it trys to addBloks
code ----------------------------------------------

PaginaHome pagHome;
Pagina pag;
BlokTekstHome blokHome ;
BlokTekst blok;
Context ctx = new InitialContext();

Object home = (PaginaHome) ctx.lookup(PaginaHome.JNDI_NAME);
pagHome = (PaginaHome) PortableRemoteObject.narrow(home, PaginaHome.class);
pag = (Pagina)pagHome.create();


Object home1 = (BlokTekstHome) ctx.lookup(BlokTekstHome.JNDI_NAME);
blokHome = (BlokTekstHome) PortableRemoteObject.narrow(home1, BlokTekstHome.class);


Object[] bloks = new Object[2];

blok = (BlokTekst) blokHome.create();
blok.setTekst("test1");
bloks[0]=blok;

blok = (BlokTekst) blokHome.create();
blok.setTekst("test2");
bloks[1]=blok;

pag.addBlok( bloks);

code-----------------------
this is the pagina class

code----------------------------------
/*
* Created on 25-aug-2004
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package sven.ent.ejb;



import java.util.Arrays;
import java.util.Collection;



import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;


import sven.ent.interfaces.BlokTekstLocal;
import sven.ent.interfaces.PaginaUtil;





/**
* @author Sven
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/

/**
* XDoclet-based CMP entity bean. This class must be declared
* <code>public abstract</code> because the concrete class will
* be implemented by the CMP provider's tooling.<br>
*
* To generate code:
* <br>
* <ul>
* <li> Add Standard EJB module to XDoclet project properties
* <li> Customize XDoclet configuration
* <li> Run XDoclet
* </ul>
* <br>
* Please see the included XDoclet Overview
* and the XDoclet Reference in the help system for details
*
* @ejb.bean name = "Pagina"
* type = "CMP"
* cmp-version = "2.x"
* display-name = "Pagina"
* description = "Pagina EJB"
* view-type = "both"
* jndi-name = "ejb/PaginaHome"
* local-jndi-name = "ejb/PaginaLocalHome"
*primkey-field = "id"
* @ejb.persistence table-name = "tpagina"
* @jboss.persistence table-name = "tpagina"
* @ejb:util
* generate="physical"
*/
public abstract class Pagina implements EntityBean {
/**
* @return Return the group this user is in.
* @ejb:interface-method view-type="both"
* @ejb:relation
* name="BloksRel"
* role-name="ZijnErBlokken"
* target-role-name="geefPagina"
* target-cascade-delete="yes"
*
*
*/
public abstract Collection getBloks();

/** @ejb:interface-method view-type="both"
*
*/
public abstract void setBloks(Collection bloks);


/**
* @ejb.interface-method view-type = "both"
* @ejb.persistence column-name = "fid"
* @ejb.pk-field
*
* @return
*/
public abstract String getId();

/**
* @ejb.interface-method view-type = "both"
*
* @param name
*/
public abstract void setId(String id);
/**
* @ejb.interface-method view-type = "both"
*
* @param Bloktekst[]
*/
public void addBlok(Object[] bloks){

setBloks(Arrays.asList((BlokTekstLocal[])bloks));
}
/**
* @ejb:interface-method view-type="both"
* @ejb ersistent-field
* @ejb.persistence column-name="ftitel"
*/
public abstract String getTitel();

/** @ejb ersistent-field
* @ejb.interface-method view-type = "both"
* */
public abstract void setTitel(String titel);


/** The EntityContext */
private EntityContext context;

/**
* @throws CreateException Thrown if the instance could not perform
* the function requested by the container because of an system-level error.
*
* @ejb.create-method
*/
public String ejbCreate() throws CreateException {

this.setId(PaginaUtil.generateGUID(this));
return null;
}

/**
* @throws EJBException Thrown if the instance could not perform
* the function requested by the container because of an system-level error.
*/
public void setEntityContext(EntityContext newContext) throws EJBException {
context = newContext;
}

/**
* This method is called with no transaction context.
*
* @throws EJBException Thrown if the instance could not perform
* the function requested by the container because of an system-level error.
*/
public void unsetEntityContext() throws EJBException {
context = null;
}
}

manny thanks for this
Hi after having a single bean running on my JBOSS server am up for the relationship ehem..
am having a Pagina bean with a collection of BlokTekst beans
when i deploy i got following err:
MBeanException: org.jboss.deployment.DeploymentException: Atleast one role of a foreign-key mapped relationship must have key fields (or <primkey-field> is missing from ejb-jar.xml): ejb-relation-name=BloksRel

here is my ejb-jar.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">

<ejb-jar >

<description><![CDATA[No Description.]]></description>
<display-name>Generated by XDoclet</display-name>

<enterprise-beans>

<!-- Session Beans -->
<!--
To add session beans that you have deployment descriptor info for, add
a file to your XDoclet merge directory called session-beans.xml that contains
the <session></session> markup for those beans.
-->

<!-- Entity Beans -->
<entity >
<description><![CDATA[Pagina EJB]]></description>
<display-name>Pagina</display-name>

<ejb-name>Pagina</ejb-name>

<home>sven.ent.interfaces.PaginaHome</home>
<remote>sven.ent.interfaces.Pagina</remote>
<local-home>sven.ent.interfaces.PaginaLocalHome</local-home>
<local>sven.ent.interfaces.PaginaLocal</local>

<ejb-class>sven.ent.ejb.PaginaCMP</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.String</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>Pagina</abstract-schema-name>
<cmp-field >
<description><![CDATA[]]></description>
<field-name>id</field-name>
</cmp-field>
<cmp-field >
<description><![CDATA[]]></description>
<field-name>titel</field-name>
</cmp-field>
<primkey-field>id</primkey-field>

<!-- Write a file named ejb-finders-Pagina.xml if you want to define extra finders. -->
</entity>

<entity >
<description><![CDATA[BlokTekst EJB]]></description>
<display-name>BlokTekst</display-name>

<ejb-name>BlokTekst</ejb-name>

<home>sven.ent.interfaces.BlokTekstHome</home>
<remote>sven.ent.interfaces.BlokTekst</remote>
<local-home>sven.ent.interfaces.BlokTekstLocalHome</local-home>
<local>sven.ent.interfaces.BlokTekstLocal</local>

<ejb-class>sven.ent.ejb.BlokTekstCMP</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.String</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>BlokTekst</abstract-schema-name>
<cmp-field >
<description><![CDATA[]]></description>
<field-name>id</field-name>
</cmp-field>
<cmp-field >
<description><![CDATA[]]></description>
<field-name>tekst</field-name>
</cmp-field>
<primkey-field>id</primkey-field>

<!-- Write a file named ejb-finders-BlokTekst.xml if you want to define extra finders. -->
</entity>

<!--
To add entity beans that you have deployment descriptor info for, add
a file to your XDoclet merge directory called entity-beans.xml that contains
the <entity></entity> markup for those beans.
-->

<!-- Message Driven Beans -->
<!--
To add message driven beans that you have deployment descriptor info for, add
a file to your XDoclet merge directory called message-driven-beans.xml that contains
the <message-driven></message-driven> markup for those beans.
-->

</enterprise-beans>

<!-- Relationships -->
<relationships >
<ejb-relation >
<ejb-relation-name>BloksRel</ejb-relation-name>

<ejb-relationship-role >
<ejb-relationship-role-name>geefPagina</ejb-relationship-role-name>
<multiplicity>Many</multiplicity>
<relationship-role-source >
<ejb-name>BlokTekst</ejb-name>
</relationship-role-source>
<cmr-field >
<cmr-field-name>pagina</cmr-field-name>
</cmr-field>
</ejb-relationship-role>

<ejb-relationship-role >
<ejb-relationship-role-name>ZijnErBlokken</ejb-relationship-role-name>
<multiplicity>One</multiplicity>
<relationship-role-source >
<ejb-name>Pagina</ejb-name>
</relationship-role-source>
<cmr-field >
<cmr-field-name>bloks</cmr-field-name>
<cmr-field-type>java.util.Collection</cmr-field-type>
</cmr-field>
</ejb-relationship-role>

</ejb-relation>
</relationships>

<!-- Assembly Descriptor -->
<assembly-descriptor >
<!--
To add additional assembly descriptor info here, add a file to your
XDoclet merge directory called assembly-descriptor.xml that contains
the <assembly-descriptor></assembly-descriptor> markup.
-->

<!-- finder permissions -->

<!-- finder permissions -->

<!-- transactions -->

<!-- finder transactions -->
</assembly-descriptor>

</ejb-jar>


thank you for your time

Sven

ooops... can someone move me to JBOSS? thanx
[ August 31, 2004: Message edited by: Sven Sven ]
17 years ago