Rick or Dain might be able to help better -- CMP is not really my thing -- but I'll give it a shot.

As far as I understand from briefly chatting with Dain is that you need the bits to specify your primary key mapping. Our CMP container is written on JPA and the end goal is to allow these kinds of things to be done via the JPA annotations or mapping file, but this is still a work in progress. For the meantime as I understand it, we still need our older OpenEJB v2 openejb-jar.xml file if any sort of mapping is required.

These two docs have small examples of the old CMP mapping.
 http://cwiki.apache.org/GMOxDOC11/very-simple-example-of-cmp-ejb.html
 http://cwiki.apache.org/GMOxDOC11/ejb-sample-application.html

I know Rick has been looking at updating some of the CMP/JPA configuration work, maybe he can comment.

-David

On May 13, 2008, at 8:31 AM, SK Leung wrote:


I have created a CMP with Tomcat 6.x+OpenEJB 3.x+OracleXE. When the program
is executed to create the object, the following error is shown.

Caused by: java.lang.Exception: <openjpa-1.0.1-r420667:592145 nonfatal
general e
rror> org.apache.openjpa.persistence.PersistenceException: Attempt to insert
nul
l into a non-nullable column: column: ID table: PRODUCTS in statement
[INSERT IN
TO PRODUCTS (productID, basePrice, description, name) VALUES (?, ?, ?, ?)]
{prep
stmnt 26620531 INSERT INTO PRODUCTS (productID, basePrice, description,
name) VA
LUES (?, ?, ?, ?) [params=(String) 123-456-7890, (double) 200.0, (String)
350 MH
z Pentium, (String) P5-300]} [code=-10, state=23000]
FailedObject: [EMAIL PROTECTED]

I think that there is a need to have a cmp field mapping to database column
configuration required but not sure. My ejb-jar.xml is as below.

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns="http://java.sun.com/xml/ns/j2ee"; version="2.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd";>
        <display-name>Hello</display-name>
        <enterprise-beans>
                <entity>
                        <ejb-name>ProductEJB</ejb-name>
                        <home>ejbuser.ProductHome</home>
                        <remote>ejbuser.Product</remote>
                        <ejb-class>ejbuser.ProductEJB</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>PRODUCTS</abstract-schema-name>
                        <cmp-field>
                                <field-name>productID</field-name>
                        </cmp-field>
                        <cmp-field>
                                <field-name>name</field-name>
                        </cmp-field>
                        <cmp-field>
                                <field-name>description</field-name>
                        </cmp-field>
                        <cmp-field>
                                <field-name>basePrice</field-name>
                        </cmp-field>
                        <primkey-field>productID</primkey-field>
                        <query>
                                <query-method>
                                        <method-name>findByName</method-name>
                                        <method-params>
                                                
<method-param>java.lang.String</method-param>
                                        </method-params>
                                </query-method>
                                <ejb-ql>SELECT DISTINCT OBJECT(p) FROM PRODUCTS 
p WHERE p.name =
?1</ejb-ql>
                        </query>
                        <query>
                                <query-method>
                                        
<method-name>findByDescription</method-name>
                                        <method-params>
                                                
<method-param>java.lang.String</method-param>
                                        </method-params>
                                </query-method>
<ejb-ql>SELECT DISTINCT OBJECT(p) FROM PRODUCTS p WHERE p.description =
?1</ejb-ql>
                        </query>
                        <query>
                                <query-method>
                                        
<method-name>findByBasePrice</method-name>
                                        <method-params>
                                                
<method-param>double</method-param>
                                        </method-params>
                                </query-method>
<ejb-ql>SELECT DISTINCT OBJECT(p) FROM PRODUCTS p WHERE p.basePrice =
?1</ejb-ql>
                        </query>
                        <query>
                                <query-method>
                                        
<method-name>findByExpensiveProducts</method-name>
                                        <method-params>
                                                
<method-param>double</method-param>
                                        </method-params>
                                </query-method>
                                <ejb-ql><![CDATA[SELECT DISTINCT OBJECT(p) FROM 
PRODUCTS p WHERE
p.basePrice > ?1]]></ejb-ql>
                        </query>
                        <query>
                                <query-method>
                                        
<method-name>findByCheapProducts</method-name>
                                        <method-params>
                                                
<method-param>double</method-param>
                                        </method-params>
                                </query-method>
                                <ejb-ql><![CDATA[SELECT DISTINCT OBJECT(p) FROM 
PRODUCTS p WHERE
p.basePrice < ?1]]></ejb-ql>
                        </query>
                        <query>
                                <query-method>
                                        
<method-name>findAllProducts</method-name>
                                        <method-params></method-params>
                                </query-method>
<ejb-ql>SELECT DISTINCT OBJECT(p) FROM PRODUCTS p WHERE p.productID IS
NOT NULL</ejb-ql>
                        </query>
                        <resource-ref>
                                
<res-ref-name>jdbc/OracleCMTadmuser</res-ref-name>
                                <res-type>javax.sql.DataSource</res-type>
                                <res-auth>Container</res-auth>
                                <res-sharing-scope>Sharable</res-sharing-scope>
                        </resource-ref>
                </entity>
        </enterprise-beans>
        <assembly-descriptor>
                <container-transaction>
                        <method>
                                <ejb-name>ProductEJB</ejb-name>
                                <method-intf>Remote</method-intf>
                                <method-name>*</method-name>
                        </method>
                        <method>
                                <ejb-name>ProductEJB</ejb-name>
                                <method-intf>Home</method-intf>
                                <method-name>*</method-name>
                        </method>
                        <trans-attribute>Required</trans-attribute>
                </container-transaction>
                <security-role>
                        <description>Users</description>
                        <role-name>users</role-name>
                </security-role>
        </assembly-descriptor>
</ejb-jar>

If a cmp mapping to database column file is required, what is the filename, its locaton and the syntax? An example is much appreciated. Much thanks.

SK
--
View this message in context: 
http://www.nabble.com/CMP-Example-with-field-mapping-file-tp17211487p17211487.html
Sent from the OpenEJB User mailing list archive at Nabble.com.



Reply via email to