tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From SK Leung <siukaile...@yahoo.com.hk>
Subject Re: CMP Example with field mapping file
Date Thu, 15 May 2008 14:37:24 GMT

After adding the key-generator, there is the error below.
Caused by: <openjpa-1.0.1-r420667:592145 fatal user error>
org.apache.openjpa.pe
rsistence.InvalidStateException: The generated value processing detected an
exis
ting value assigned to this field: openejb.ejbuser.PRODUCTS.productID.  This
exi
sting value was either provided via an initializer or by calling the setter
meth
od.  You either need to remove the @GeneratedValue annotation or modify the
code
 to remove the initializer processing.

I have tried to retrieve the records from database but got nothing. Actually
I have configured to have two entities - one BMP and one CMP (this is the
one in problem). The database connection for BMP works fine, so that I
configure the CMP the same way as BMP as shown in the ejb-jar.xml listed at
the end. I doubt whether the database connect method for CMP is different.
Please advise what is the correct way for connecting the CMP to Oracle
database in OpenEJB. Much thanks.

SK
content of ejb-jar.xml:
<?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>
			<display-name>AccountEJB</display-name>
			<ejb-name>AccountEJB</ejb-name>
			<home>ejbuser.AccountHome</home>
			<remote>ejbuser.Account</remote>
			<ejb-class>ejbuser.AccountEJB</ejb-class>
			<persistence-type>Bean</persistence-type>
			<prim-key-class>ejbuser.AccountPK</prim-key-class>
			<reentrant>False</reentrant>
			<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>
		<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>


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


Mime
View raw message