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