I can't seem to find any good examples of this which is strange since it is a very common situation. Try adding this to your file (after the last cmp-field-mapping):

<key-generator xmlns="http://www.openejb.org/xml/ns/ pkgen-2.1">
            <uuid/>
          </key-generator>

As I mentioned in another email, the actual contents of the key- generator element is ignored, but when we see the element we add @javax.persistence.GeneratedValue(strategy=IDENTITY) to the primary key field. This causes OpenJPA to use the database generated identity for the primary key of the entity.

-dain

On May 14, 2008, at 7:32 AM, SK Leung wrote:


I have created the openejb-jar.xml file as below.

<?xml version="1.0" encoding="UTF-8"?>
<openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1";
xmlns:nam="http://geronimo.apache.org/xml/ns/naming-1.1";
xmlns:pkgen="http//www.openejb.org/xml/ns/pkgen-2.0"
xmlns:sec="http://geronimo.apache.org/xml/ns/security-1.1";
xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.1";>
        <cmp-connection-factory>
                <resource-link>jdbc/OracleCMTadmuser</resource-link>
        </cmp-connection-factory>
        <enterprise-beans>
                <entity>
                        <ejb-name>ProductEJB</ejb-name>
                        <table-name>PRODUCTS</table-name>
                        <cmp-field-mapping>
                                <cmp-field-name>productID</cmp-field-name>
                                <table-column>PRODUCTID</table-column>
                        </cmp-field-mapping>
                        <cmp-field-mapping>
                                <cmp-field-name>name</cmp-field-name>
                                <table-column>NAME</table-column>
                        </cmp-field-mapping>
                        <cmp-field-mapping>
                                <cmp-field-name>description</cmp-field-name>
                                <table-column>DESCRIPTION</table-column>
                        </cmp-field-mapping>
                        <cmp-field-mapping>
                                <cmp-field-name>basePrice</cmp-field-name>
                                <table-column>BASEPRICE</table-column>
                        </cmp-field-mapping>
                </entity>
        </enterprise-beans>
</openejb-jar>

But the same error message is shown when creating the object. I have the
following resource defined in openejb.xml.

<Resource id="jdbc/OracleCMTadmuser" type="DataSource">
 JdbcDriver oracle.jdbc.driver.OracleDriver
 JdbcUrl jdbc:oracle:thin:@localhost:1521:xe
 UserName adm_user
 Password password
</Resource>

I do not know whether the problem is in making connection to database or creating the record. If it is the latter one, then what is the cause for such error? I even try to insert all nulls into the table and it accepts.
Please give help, much thanks.

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


Reply via email to