From user-return-7504-apmail-geronimo-user-archive=geronimo.apache.org@geronimo.apache.org Thu Sep 06 12:57:09 2007 Return-Path: Delivered-To: apmail-geronimo-user-archive@www.apache.org Received: (qmail 7175 invoked from network); 6 Sep 2007 12:57:08 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 6 Sep 2007 12:57:08 -0000 Received: (qmail 76640 invoked by uid 500); 6 Sep 2007 12:57:00 -0000 Delivered-To: apmail-geronimo-user-archive@geronimo.apache.org Received: (qmail 76617 invoked by uid 500); 6 Sep 2007 12:57:00 -0000 Mailing-List: contact user-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: user@geronimo.apache.org List-Id: Delivered-To: mailing list user@geronimo.apache.org Received: (qmail 76606 invoked by uid 99); 6 Sep 2007 12:56:59 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 06 Sep 2007 05:56:59 -0700 X-ASF-Spam-Status: No, hits=4.9 required=10.0 tests=HTML_MESSAGE,MIME_HTML_ONLY,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [208.109.78.207] (HELO smtpoutwbe05.prod.mesa1.secureserver.net) (208.109.78.207) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 06 Sep 2007 12:58:14 +0000 Received: (qmail 23803 invoked from network); 6 Sep 2007 12:56:31 -0000 Received: from unknown (HELO gem-wbe21.prod.mesa1.secureserver.net) (64.202.189.205) by smtpoutwbe05.prod.mesa1.secureserver.net with SMTP; 6 Sep 2007 12:56:31 -0000 Received: (qmail 28891 invoked by uid 99); 6 Sep 2007 12:56:31 -0000 Date: Thu, 06 Sep 2007 05:56:31 -0700 From: Mark Aufdencamp Subject: RE: CMP/CMR 2.1 EJBCreate EJBPostCreate To: user@geronimo.apache.org Message-ID: <20070906055631.181451e9c2a7ebbcd6ae28cea81146c8.43982c536b.wbe@email.secureserver.net> MIME-Version: 1.0 Content-Type: TEXT/html; CHARSET=US-ASCII User-Agent: Web-Based Email 4.10.20 X-Originating-IP: 76.202.40.249 X-Virus-Checked: Checked by ClamAV on apache.org
Efren, Thank you!  The answers to my questions are, I believe, now answered.
 
I don't have a <container-transaction> section in my ejb-jar.xml  I'm guessing this results in an immediate INSERT on the EJBCreate without a TRANSACTION wrapper around the EJBCreate/EJBPostCreate.  Thus, the INSERT will get rejected.
 
I'll modify my ejb-jar.xml today and let you all know.
-------- Original Message --------
Subject: Re: CMP/CMR 2.1 EJBCreate EJBPostCreate
From: Efren Gonzalez <gonzale@tutopia.com>
Date: Thu, September 06, 2007 2:53 am
To: user@geronimo.apache.org

Hello

I have been able to have 2.1 CMP Entity EJB's with CMR working with
Websphere Community Edition 1.0 (which is Geronimo 1.0 anyway), MySQL
5.0 InnoDB tables and NOT NULL constraints, I think this is exactly what
you want to accomplish.

I'm not sure what may be missing so I'll post a complete example, this
is actually taken from a working application (Interfaces and non
relevant code ommited).

--- START ejb-jar.xml ---
<enterprise-beans>
<entity>
<ejb-name>Tipo</ejb-name>
<local-home>com.mx.jlr.crm.ejb.entity.tipo.TipoLocalHome</local-home>
<local>com.mx.jlr.crm.ejb .entity.tipo.TipoLocal</local>
<ejb-class>com.mx.jlr.crm.ejb.entity.tipo.TipoBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.Integer</prim-key-class>
<reentrant>false</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>tipos</abstract-schema-name>

<cmp-field>
<field-name>idTipo</field-name>
</cmp-field>
<cmp-field>
<field-name>idMarca</field-name>
</cmp-field>
<cmp-field>
<field-name>nombreTipo</field-name>
</cmp-field>
<primkey-field>idTipo</primkey-field>
</entity>

<entity>
<ejb-name>Marca</ejb-name>
<local-home>com.mx.jlr.crm.ejb.entity.marca.MarcaLocalHome</local-home>
<local>com.mx.jlr.crm.ejb.entity.marca.MarcaLocal</local>
<ejb-clas s>com.mx.jlr.crm.ejb.entity.marca.MarcaBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.Integer</prim-key-class>
<reentrant>false</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>marcas</abstract-schema-name>

<cmp-field>
<field-name>idMarca</field-name>
</cmp-field>
<cmp-field>
<field-name>nombreMarca</field-name>
</cmp-field>
<primkey-field>idMarca</primkey-field>
</entity>
</enterprise-beans>

<relationships>
<ejb-relation>
<ejb-relation-name>marcas-tipos</ejb-relation-name>
<ejb-relationship-role>
<ejb-relationship-role-name>marcas</ejb-relationship-role-name>
<multiplicity>One</multiplicity>
<relationship-role-source>
<ejb-name>Marca</ej b-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>tipos</cmr-field-name>
<cmr-field-type>java.util.Collection</cmr-field-type>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>tipos</ejb-relationship-role-name>
<multiplicity>Many</multiplicity>
<relationship-role-source>
<ejb-name>Tipo</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>marca</cmr-field-name>
</cmr-field>
</ejb-relationship-role>
</ejb-relation>
</relationships>

<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>Marca</ejb-name>
<method-name>*</method-name>
</method>
<method>
<ejb-name>Tipo</ejb-name>
<method-name>*</method- name>
</method>

<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>
--- END ejb-jar.xml ---

--- START openejb-jar.xml ---
<enforce-foreign-key-constraints />

<enterprise-beans>
<entity>
<ejb-name>Marca</ejb-name>
<local-jndi-name>ejb/Marca</local-jndi-name>
<table-name>marcas</table-name>
<cmp-field-mapping>
<cmp-field-name>idMarca</cmp-field-name>
<table-column>id_marca</table-column>
</cmp-field-mapping>
<cmp-field-mapping>
<cmp-field-name>nombreMarca</cmp-field-name>
<table-column>nombre_marca</table-column>
</cmp-field-mapping>
<pkgen:key-generator>
<pkgen:sequence-table>
<pkgen:table-name>sequence_table</pkgen:table-name>
<pkgen:sequence-name>Marca</pkgen:sequ ence-name>
<pkgen:batch-size>1</pkgen:batch-size>
</pkgen:sequence-table>
</pkgen:key-generator>
</entity>

<entity>
<ejb-name>Tipo</ejb-name>
<jndi-name>ejb/Tipo</jndi-name>
<table-name>tipos</table-name>
<cmp-field-mapping>
<cmp-field-name>idTipo</cmp-field-name>
<table-column>id_tipo</table-column>
</cmp-field-mapping>
<cmp-field-mapping>
<cmp-field-name>idMarca</cmp-field-name>
<table-column>id_marca</table-column>
</cmp-field-mapping>
<cmp-field-mapping>
<cmp-field-name>nombreTipo</cmp-field-name>
<table-column>nombre_tipo</table-column>
</cmp-field-mapping>
<pkgen:key-generator>
<pkgen:sequence-table>
<pkgen:table-name>sequence_table</pkgen:table-name>
<pkgen:sequence-name>Tipo</pkge n:sequence-name>
<pkgen:batch-size>1</pkgen:batch-size>
</pkgen:sequence-table>
</pkgen:key-generator>
</entity>
</enterprise-beans>

<relationships>
<ejb-relation>
<ejb-relation-name>marcas-tipos</ejb-relation-name>
<ejb-relationship-role>
<ejb-relationship-role-name>marcas</ejb-relationship-role-name>
<relationship-role-source>
<ejb-name>Marca</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>tipos</cmr-field-name>
</cmr-field>
<role-mapping>
<cmr-field-mapping>
<key-column>id_marca</key-column>
<foreign-key-column>id_marca</foreign-key-column>
</cmr-field-mapping>
</role-mapping>
</ejb-relationship-role>
</ejb-relation>

<ejb-relation>
<ejb-relation-name>tipos-marcas</ejb- relation-name>
<ejb-relationship-role>
<ejb-relationship-role-name>tipos</ejb-relationship-role-name>
<relationship-role-source>
<ejb-name>Tipo</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>marca</cmr-field-name>
</cmr-field>
<foreign-key-column-on-source />
<role-mapping>
<cmr-field-mapping>
<key-column>id_marca</key-column>
<foreign-key-column>id_marca</foreign-key-column>
</cmr-field-mapping>
</role-mapping>
</ejb-relationship-role>
</ejb-relation>
</relationships>
--- END openejb-jar.xml ---

--- START MarcaBean.java ---
public abstract class MarcaBean implements EntityBean {
public abstract void setIdMarca(Integer idMarca);
public abstract Integer getIdMarca();
public abstract void setNombreMarca(String nombreMarca);
public abstract S tring getNombreMarca();
public abstract void setTipos(Collection tipos);
public abstract Collection getTipos();

public Integer ejbCreate(String nombreMarca) throws CreateException {
setNombreMarca(nombreMarca);

return null;
}

public void ejbPostCreate(String nombreMarca) {
// Nada
}
}
--- END MarcaBean.java ---

--- START TipoBean.java ---
public abstract class TipoBean implements EntityBean {
public abstract void setIdTipo(Integer idTipo);
public abstract Integer getIdTipo();
public abstract void setMarca(MarcaLocal marca);
public abstract MarcaLocal getMarca();
public abstract void setIdMarca(Integer idMarca);
public abstract Integer getIdMarca();
public abstract void setNombreTipo(String nombreTipo);
public abstract String getNombreTipo();

public Integer ejbCreate(MarcaLocal marca, String nombreTipo) throws
CreateException {
setNombreTipo(nombreTipo);

return null;
}
public void ejbPostCreate(MarcaLocal marca, String nombreTipo) {
setMarca(marca);
}
}
--- END TipoBean.java ---

--- START Marcas.sql ---
CREATE TABLE `marcas` (
`id_marca` int(10) unsigned NOT NULL,
`nombre_marca` varchar(25) NOT NULL,
PRIMARY KEY (`id_marca`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--- END Marcas.sql ---

--- START Tipos.sql ---
CREATE TABLE `tipos` (
`id_tipo` int(10) unsigned NOT NULL,
`id_marca` int(10) unsigned NOT NULL,
`nombre_tipo` varchar(25) NOT NULL,
PRIMARY KEY (`id_tipo`),
KEY `IDX_MARCA` (`id_marca`),
CONSTRAINT `FK_MARCAS_TIPOS` FOREIGN KEY (`id_marca`) REFERENCES
`marcas` (`id_marca`) ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--- END Tipos.sql ---

I think I'm not missing anything, at least I don't remember making any
special configuration.

Hope this helps...

Regards,
Efrén

Mark Aufdencamp escribió:
> H i All,
>
> I'm still wondering about control of the SQL INSERT statement when an
> EJBCreate is executed. Specifically, how can it be defined properly to
> allow the setting of CMR Relationships on Foreign Key Columns that are
> defined as NOT NULL. JBoss and WebLogic both possess a container
> configuration command that effectively delays the SQL INSERT until after
> the EJBPostCreate has been executed to specifically allow for this
> behavior.
>
> I've removed the NOT NULL constraint on my Database Schema, and it
> functions properly with the EJBCreate setting the Primary Key, and the
> EJBPostCreate setting the Foreign Key with the CMR Entity. I've checked
> to insure the MySQL tables are defined as InnoDB, so they should support
> Transaction Management. I've attempted to add the open-ejb.xml
> configuration command, <enforce-foreign-key-constraints>, as suggested
> by David Carew, but sadly this had no apparent effect.
>
> Can this be done or is it an uncovered bust in the 2.1 specs?
>
> Am I missing something maybe in the Transaction Management realm that I
> dont have configured to have this function?
>
> Anyone engaged in the this type of Create/PostCreate with NOT NULL
> Foreign Keys on a different database and JDBC driver, say Derby?
>
> Thanks to All for suggestions,
>
> Mark Aufdencamp
> Mark@Aufdencamp.com
>
>
>
>