geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Aufdencamp <m...@aufdencamp.com>
Subject RE: CMP/CMR 2.1 EJBCreate EJBPostCreate
Date Thu, 06 Sep 2007 12:56:31 GMT
<html><body><DIV>Efren, Thank you!&nbsp; The answers to my questions
are, I believe, now answered.</DIV>
<DIV>&nbsp;</DIV>
<DIV>I don't have a &lt;container-transaction&gt; section in my ejb-jar.xml&nbsp;
I'm guessing this results in an immediate INSERT on the EJBCreate without a TRANSACTION wrapper
around the EJBCreate/EJBPostCreate.&nbsp; Thus, the INSERT will get rejected.</DIV>
<DIV>&nbsp;</DIV>
<DIV>I'll modify my ejb-jar.xml today and let you all know.</DIV>
<div     >
<BLOCKQUOTE style="PADDING-LEFT: 8px; MARGIN-LEFT: 8px; BORDER-LEFT: blue 2px solid" webmail="1">--------
Original Message --------<BR>Subject: Re: CMP/CMR 2.1 EJBCreate EJBPostCreate<BR>From:
Efren Gonzalez &lt;gonzale@tutopia.com&gt;<BR>Date: Thu, September 06, 2007
2:53 am<BR>To: user@geronimo.apache.org<BR><BR>Hello<BR><BR>I
have been able to have 2.1 CMP Entity EJB's with CMR working with <BR>Websphere Community
Edition 1.0 (which is Geronimo 1.0 anyway), MySQL <BR>5.0 InnoDB tables and NOT NULL
constraints, I think this is exactly what <BR>you want to accomplish.<BR><BR>I'm
not sure what may be missing so I'll post a complete example, this <BR>is actually taken
from a working application (Interfaces and non <BR>relevant code ommited).<BR><BR>---
START ejb-jar.xml ---<BR>&lt;enterprise-beans&gt;<BR>&lt;entity&gt;<BR>&lt;ejb-name&gt;Tipo&lt;/ejb-name&gt;<BR>&lt;local-home&gt;com.mx.jlr.crm.ejb.entity.tipo.TipoLocalHome&lt;/local-home&gt;<BR>&lt;local&gt;com.mx.jlr.crm.ejb
 .entity.tipo.TipoLocal&lt;/local&gt;<BR>&lt;ejb-class&gt;com.mx.jlr.crm.ejb.entity.tipo.TipoBean&lt;/ejb-class&gt;<BR>&lt;persistence-type&gt;Container&lt;/persistence-type&gt;<BR>&lt;prim-key-class&gt;java.lang.Integer&lt;/prim-key-class&gt;<BR>&lt;reentrant&gt;false&lt;/reentrant&gt;<BR>&lt;cmp-version&gt;2.x&lt;/cmp-version&gt;<BR>&lt;abstract-schema-name&gt;tipos&lt;/abstract-schema-name&gt;<BR><BR>&lt;cmp-field&gt;<BR>&lt;field-name&gt;idTipo&lt;/field-name&gt;<BR>&lt;/cmp-field&gt;<BR>&lt;cmp-field&gt;<BR>&lt;field-name&gt;idMarca&lt;/field-name&gt;<BR>&lt;/cmp-field&gt;<BR>&lt;cmp-field&gt;<BR>&lt;field-name&gt;nombreTipo&lt;/field-name&gt;<BR>&lt;/cmp-field&gt;<BR>&lt;primkey-field&gt;idTipo&lt;/primkey-field&gt;<BR>&lt;/entity&gt;<BR><BR>&lt;entity&gt;<BR>&lt;ejb-name&gt;Marca&lt;/ejb-name&gt;<BR>&lt;local-home&gt;com.mx.jlr.crm.ejb.entity.marca.MarcaLocalHome&lt;/local-home&gt;<BR>&lt;local&gt;com.mx.jlr.crm.ejb.entity.marca.MarcaLocal&lt;/local&gt;<BR>&lt;ejb-clas
 s&gt;com.mx.jlr.crm.ejb.entity.marca.MarcaBean&lt;/ejb-class&gt;<BR>&lt;persistence-type&gt;Container&lt;/persistence-type&gt;<BR>&lt;prim-key-class&gt;java.lang.Integer&lt;/prim-key-class&gt;<BR>&lt;reentrant&gt;false&lt;/reentrant&gt;<BR>&lt;cmp-version&gt;2.x&lt;/cmp-version&gt;<BR>&lt;abstract-schema-name&gt;marcas&lt;/abstract-schema-name&gt;<BR><BR>&lt;cmp-field&gt;<BR>&lt;field-name&gt;idMarca&lt;/field-name&gt;<BR>&lt;/cmp-field&gt;<BR>&lt;cmp-field&gt;<BR>&lt;field-name&gt;nombreMarca&lt;/field-name&gt;<BR>&lt;/cmp-field&gt;<BR>&lt;primkey-field&gt;idMarca&lt;/primkey-field&gt;<BR>&lt;/entity&gt;<BR>&lt;/enterprise-beans&gt;<BR><BR>&lt;relationships&gt;<BR>&lt;ejb-relation&gt;<BR>&lt;ejb-relation-name&gt;marcas-tipos&lt;/ejb-relation-name&gt;<BR>&lt;ejb-relationship-role&gt;<BR>&lt;ejb-relationship-role-name&gt;marcas&lt;/ejb-relationship-role-name&gt;<BR>&lt;multiplicity&gt;One&lt;/multiplicity&gt;<BR>&lt;relationship-role-source&gt;<BR>&lt;ejb-name&gt;Marca&lt;/ej
 b-name&gt;<BR>&lt;/relationship-role-source&gt;<BR>&lt;cmr-field&gt;<BR>&lt;cmr-field-name&gt;tipos&lt;/cmr-field-name&gt;<BR>&lt;cmr-field-type&gt;java.util.Collection&lt;/cmr-field-type&gt;<BR>&lt;/cmr-field&gt;<BR>&lt;/ejb-relationship-role&gt;<BR>&lt;ejb-relationship-role&gt;<BR>&lt;ejb-relationship-role-name&gt;tipos&lt;/ejb-relationship-role-name&gt;<BR>&lt;multiplicity&gt;Many&lt;/multiplicity&gt;<BR>&lt;relationship-role-source&gt;<BR>&lt;ejb-name&gt;Tipo&lt;/ejb-name&gt;<BR>&lt;/relationship-role-source&gt;<BR>&lt;cmr-field&gt;<BR>&lt;cmr-field-name&gt;marca&lt;/cmr-field-name&gt;<BR>&lt;/cmr-field&gt;<BR>&lt;/ejb-relationship-role&gt;<BR>&lt;/ejb-relation&gt;<BR>&lt;/relationships&gt;<BR><BR>&lt;assembly-descriptor&gt;<BR>&lt;container-transaction&gt;<BR>&lt;method&gt;<BR>&lt;ejb-name&gt;Marca&lt;/ejb-name&gt;<BR>&lt;method-name&gt;*&lt;/method-name&gt;<BR>&lt;/method&gt;<BR>&lt;method&gt;<BR>&lt;ejb-name&gt;Tipo&lt;/ejb-name&gt;<BR>&lt;method-name&gt;*&lt;/method-
 name&gt;<BR>&lt;/method&gt;<BR><BR>&lt;trans-attribute&gt;Required&lt;/trans-attribute&gt;<BR>&lt;/container-transaction&gt;<BR>&lt;/assembly-descriptor&gt;<BR>---
END ejb-jar.xml ---<BR><BR>--- START openejb-jar.xml ---<BR>&lt;enforce-foreign-key-constraints
/&gt;<BR><BR>&lt;enterprise-beans&gt;<BR>&lt;entity&gt;<BR>&lt;ejb-name&gt;Marca&lt;/ejb-name&gt;<BR>&lt;local-jndi-name&gt;ejb/Marca&lt;/local-jndi-name&gt;<BR>&lt;table-name&gt;marcas&lt;/table-name&gt;<BR>&lt;cmp-field-mapping&gt;<BR>&lt;cmp-field-name&gt;idMarca&lt;/cmp-field-name&gt;<BR>&lt;table-column&gt;id_marca&lt;/table-column&gt;<BR>&lt;/cmp-field-mapping&gt;<BR>&lt;cmp-field-mapping&gt;<BR>&lt;cmp-field-name&gt;nombreMarca&lt;/cmp-field-name&gt;<BR>&lt;table-column&gt;nombre_marca&lt;/table-column&gt;<BR>&lt;/cmp-field-mapping&gt;<BR>&lt;pkgen:key-generator&gt;<BR>&lt;pkgen:sequence-table&gt;<BR>&lt;pkgen:table-name&gt;sequence_table&lt;/pkgen:table-name&gt;<BR>&lt;pkgen:sequence-name&gt;Marca&lt;/pkgen:sequ
 ence-name&gt;<BR>&lt;pkgen:batch-size&gt;1&lt;/pkgen:batch-size&gt;<BR>&lt;/pkgen:sequence-table&gt;<BR>&lt;/pkgen:key-generator&gt;<BR>&lt;/entity&gt;<BR><BR>&lt;entity&gt;<BR>&lt;ejb-name&gt;Tipo&lt;/ejb-name&gt;<BR>&lt;jndi-name&gt;ejb/Tipo&lt;/jndi-name&gt;<BR>&lt;table-name&gt;tipos&lt;/table-name&gt;<BR>&lt;cmp-field-mapping&gt;<BR>&lt;cmp-field-name&gt;idTipo&lt;/cmp-field-name&gt;<BR>&lt;table-column&gt;id_tipo&lt;/table-column&gt;<BR>&lt;/cmp-field-mapping&gt;<BR>&lt;cmp-field-mapping&gt;<BR>&lt;cmp-field-name&gt;idMarca&lt;/cmp-field-name&gt;<BR>&lt;table-column&gt;id_marca&lt;/table-column&gt;<BR>&lt;/cmp-field-mapping&gt;<BR>&lt;cmp-field-mapping&gt;<BR>&lt;cmp-field-name&gt;nombreTipo&lt;/cmp-field-name&gt;<BR>&lt;table-column&gt;nombre_tipo&lt;/table-column&gt;<BR>&lt;/cmp-field-mapping&gt;<BR>&lt;pkgen:key-generator&gt;<BR>&lt;pkgen:sequence-table&gt;<BR>&lt;pkgen:table-name&gt;sequence_table&lt;/pkgen:table-name&gt;<BR>&lt;pkgen:sequence-name&gt;Tipo&lt;/pkge
 n:sequence-name&gt;<BR>&lt;pkgen:batch-size&gt;1&lt;/pkgen:batch-size&gt;<BR>&lt;/pkgen:sequence-table&gt;<BR>&lt;/pkgen:key-generator&gt;<BR>&lt;/entity&gt;<BR>&lt;/enterprise-beans&gt;<BR><BR>&lt;relationships&gt;<BR>&lt;ejb-relation&gt;<BR>&lt;ejb-relation-name&gt;marcas-tipos&lt;/ejb-relation-name&gt;<BR>&lt;ejb-relationship-role&gt;<BR>&lt;ejb-relationship-role-name&gt;marcas&lt;/ejb-relationship-role-name&gt;<BR>&lt;relationship-role-source&gt;<BR>&lt;ejb-name&gt;Marca&lt;/ejb-name&gt;<BR>&lt;/relationship-role-source&gt;<BR>&lt;cmr-field&gt;<BR>&lt;cmr-field-name&gt;tipos&lt;/cmr-field-name&gt;<BR>&lt;/cmr-field&gt;<BR>&lt;role-mapping&gt;<BR>&lt;cmr-field-mapping&gt;<BR>&lt;key-column&gt;id_marca&lt;/key-column&gt;<BR>&lt;foreign-key-column&gt;id_marca&lt;/foreign-key-column&gt;<BR>&lt;/cmr-field-mapping&gt;<BR>&lt;/role-mapping&gt;<BR>&lt;/ejb-relationship-role&gt;<BR>&lt;/ejb-relation&gt;<BR><BR>&lt;ejb-relation&gt;<BR>&lt;ejb-relation-name&gt;tipos-marcas&lt;/ejb-
 relation-name&gt;<BR>&lt;ejb-relationship-role&gt;<BR>&lt;ejb-relationship-role-name&gt;tipos&lt;/ejb-relationship-role-name&gt;<BR>&lt;relationship-role-source&gt;<BR>&lt;ejb-name&gt;Tipo&lt;/ejb-name&gt;<BR>&lt;/relationship-role-source&gt;<BR>&lt;cmr-field&gt;<BR>&lt;cmr-field-name&gt;marca&lt;/cmr-field-name&gt;<BR>&lt;/cmr-field&gt;<BR>&lt;foreign-key-column-on-source
/&gt;<BR>&lt;role-mapping&gt;<BR>&lt;cmr-field-mapping&gt;<BR>&lt;key-column&gt;id_marca&lt;/key-column&gt;<BR>&lt;foreign-key-column&gt;id_marca&lt;/foreign-key-column&gt;<BR>&lt;/cmr-field-mapping&gt;<BR>&lt;/role-mapping&gt;<BR>&lt;/ejb-relationship-role&gt;<BR>&lt;/ejb-relation&gt;<BR>&lt;/relationships&gt;<BR>---
END openejb-jar.xml ---<BR><BR>--- START MarcaBean.java ---<BR>public abstract
class MarcaBean implements EntityBean {<BR>public abstract void setIdMarca(Integer idMarca);<BR>public
abstract Integer getIdMarca();<BR>public abstract void setNombreMarca(String nombreMarca);<BR>public
abstract S
 tring getNombreMarca();<BR>public abstract void setTipos(Collection tipos);<BR>public
abstract Collection getTipos();<BR><BR>public Integer ejbCreate(String nombreMarca)
throws CreateException {<BR>setNombreMarca(nombreMarca);<BR><BR>return null;<BR>}<BR><BR>public
void ejbPostCreate(String nombreMarca) {<BR>// Nada<BR>}<BR>}<BR>---
END MarcaBean.java ---<BR><BR>--- START TipoBean.java ---<BR>public abstract
class TipoBean implements EntityBean {<BR>public abstract void setIdTipo(Integer idTipo);<BR>public
abstract Integer getIdTipo();<BR>public abstract void setMarca(MarcaLocal marca);<BR>public
abstract MarcaLocal getMarca();<BR>public abstract void setIdMarca(Integer idMarca);<BR>public
abstract Integer getIdMarca();<BR>public abstract void setNombreTipo(String nombreTipo);<BR>public
abstract String getNombreTipo();<BR><BR>public Integer ejbCreate(MarcaLocal marca,
String nombreTipo) throws <BR>CreateException {<BR>setNombreTipo(nombreTipo);<BR><BR>return
null;<BR>}<BR><B
 R>public void ejbPostCreate(MarcaLocal marca, String nombreTipo) {<BR>setMarca(marca);<BR>}<BR>}<BR>---
END TipoBean.java ---<BR><BR>--- START Marcas.sql ---<BR>CREATE TABLE `marcas`
(<BR>`id_marca` int(10) unsigned NOT NULL,<BR>`nombre_marca` varchar(25) NOT NULL,<BR>PRIMARY
KEY (`id_marca`)<BR>) ENGINE=InnoDB DEFAULT CHARSET=utf8;<BR>--- END Marcas.sql
---<BR><BR>--- START Tipos.sql ---<BR>CREATE TABLE `tipos` (<BR>`id_tipo`
int(10) unsigned NOT NULL,<BR>`id_marca` int(10) unsigned NOT NULL,<BR>`nombre_tipo`
varchar(25) NOT NULL,<BR>PRIMARY KEY (`id_tipo`),<BR>KEY `IDX_MARCA` (`id_marca`),<BR>CONSTRAINT
`FK_MARCAS_TIPOS` FOREIGN KEY (`id_marca`) REFERENCES <BR>`marcas` (`id_marca`) ON UPDATE
CASCADE<BR>) ENGINE=InnoDB DEFAULT CHARSET=utf8;<BR>--- END Tipos.sql ---<BR><BR>I
think I'm not missing anything, at least I don't remember making any <BR>special configuration.<BR><BR>Hope
this helps...<BR><BR>Regards,<BR>Efr&eacute;n<BR><BR>Mark
Aufdencamp escribi&oacute;:<BR>&gt; H
 i All,<BR>&gt; <BR>&gt; I'm still wondering about control of the SQL
INSERT statement when an<BR>&gt; EJBCreate is executed. Specifically, how can it
be defined properly to<BR>&gt; allow the setting of CMR Relationships on Foreign
Key Columns that are<BR>&gt; defined as NOT NULL. JBoss and WebLogic both possess
a container<BR>&gt; configuration command that effectively delays the SQL INSERT
until after<BR>&gt; the EJBPostCreate has been executed to specifically allow for
this<BR>&gt; behavior.<BR>&gt; <BR>&gt; I've removed the NOT
NULL constraint on my Database Schema, and it<BR>&gt; functions properly with the
EJBCreate setting the Primary Key, and the<BR>&gt; EJBPostCreate setting the Foreign
Key with the CMR Entity. I've checked<BR>&gt; to insure the MySQL tables are defined
as InnoDB, so they should support<BR>&gt; Transaction Management. I've attempted
to add the open-ejb.xml<BR>&gt; configuration command, &lt;enforce-foreign-key-constraints&gt;,
as suggested<BR>&gt; by
  David Carew, but sadly this had no apparent effect.<BR>&gt; <BR>&gt;
Can this be done or is it an uncovered bust in the 2.1 specs? <BR>&gt; <BR>&gt;
Am I missing something maybe in the Transaction Management realm that I<BR>&gt;
dont have configured to have this function?<BR>&gt; <BR>&gt; Anyone engaged
in the this type of Create/PostCreate with NOT NULL<BR>&gt; Foreign Keys on a different
database and JDBC driver, say Derby?<BR>&gt; <BR>&gt; Thanks to All for
suggestions,<BR>&gt; <BR>&gt; Mark Aufdencamp<BR>&gt; <A
onclick="Popup.composeWindow('pcompose.php?sendto=Mark%40Aufdencamp.com'); return false;"
href="http://email.secureserver.net/pcompose.php?aEmlPart=0&amp;type=replyall&amp;folder=INBOX.Apache.Geronimo.Users&amp;uid=887#Compose">Mark<B></B>@Aufdencamp.com</A><BR>&gt;
<BR>&gt; <BR>&gt; <BR>&gt; <BR></BLOCKQUOTE></DIV></body></html>

Mime
View raw message