http://www.roseindia.net
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Please visit our lastest forum and start dicussing the topics
a cmr-field and a cmp-field on the bean are using the same

 
Post new topic   Reply to topic    http://www.roseindia.net Forum Index -> EJB - Enterprise Java Beans
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Mon Apr 02, 2007 9:11 pm    Post subject: a cmr-field and a cmp-field on the bean are using the same Reply with quote

Hi:

I am using weblogic 8.1 and MyEclipse 5.1.1. I am deploying my ear application through MyEclipse 5.1.1 as an ear file.
When I ran the following EJB QL:
SELECT OBJECT(p) FROM Product p.category = ?1
I get the following error:
n relation Category-Product, a cmr-field and a cmp-field on the bean are using the same name. The names of cmr and cmp fields must be unique.


It is basically complaining that I have a field
<cmr-field>
<cmr-field-name>category</cmr-field-name>
</cmr-field>

in my ejb-jar.xml and also the same category in the
<cmp-field><field-name>category</field-name></cmp-field>

field. The problem is that if I changed the value of the cmr-field, I have to add a get and set in my productLocal.java and when you do that you have to do the same in the ejb-jar.xml.

Here is my ejb-jar.xml:
<?xml version="1.0"?>

<!DOCTYPE ejb-jar PUBLIC
"-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"
"http://java.sun.com/dtd/ejb-jar_2_0.dtd">

<ejb-jar>
<enterprise-beans>
<entity>
<ejb-name>CategoryEJB</ejb-name>
<local-home>com.CategoryHomeLocal</local-home>
<local>com.CategoryLocal</local>
<ejb-class>com.CategoryBean</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>Category</abstract-schema-name>
<cmp-field><field-name>categoryId</field-name></cmp-field>
<cmp-field><field-name>categoryName</field-name></cmp-field>
<cmp-field><field-name>picture</field-name></cmp-field>
<cmp-field><field-name>pictureWidth</field-name></cmp-field>
<cmp-field><field-name>pictureHeight</field-name></cmp-field>
<cmp-field><field-name>labelOn</field-name></cmp-field>
<cmp-field><field-name>labelOff</field-name></cmp-field>
<cmp-field><field-name>button</field-name></cmp-field>

<primkey-field>categoryId</primkey-field>
<security-identity><use-caller-identity/></security-identity>
<query>
<query-method>
<method-name>findCategory</method-name>
<method-params></method-params>
</query-method>
<ejb-ql>
SELECT OBJECT(c) FROM Category c
</ejb-ql>
</query>
</entity>
<entity>
<ejb-name>ProductEJB</ejb-name>
<local-home>com.ProductHomeLocal</local-home>
<local>com.ProductLocal</local>
<ejb-class>com.ProductBean</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>Product</abstract-schema-name>
<cmp-field><field-name>productId</field-name></cmp-field>
<cmp-field><field-name>brandName</field-name></cmp-field>
<cmp-field><field-name>productDescription</field-name></cmp-field>
<cmp-field><field-name>purchasePrice</field-name></cmp-field>
<cmp-field><field-name>category</field-name></cmp-field>

<primkey-field>productId</primkey-field>
<security-identity><use-caller-identity/></security-identity>
<query>
<query-method>
<method-name>findProduct</method-name>
<method-params>
<method-param>com.CategoryLocal</method-param>
</method-params>
</query-method>
<ejb-ql>
SELECT OBJECT(p) FROM Product p.category = ?1
</ejb-ql>
</query>
</entity>
</enterprise-beans>
<relationships>
<ejb-relation>
<ejb-relation-name>Category-Product</ejb-relation-name>
<ejb-relationship-role>
<ejb-relationship-role-name>
Category-has-many-Product-numbers
</ejb-relationship-role-name>
<multiplicity>one</multiplicity>
<relationship-role-source>
<ejb-name>CategoryEJB</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>productNumbers</cmr-field-name>
<cmr-field-type>java.util.Collection</cmr-field-type>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>
Product-belongs-to-Category
</ejb-relationship-role-name>
<multiplicity>many</multiplicity>
<cascade-delete/>
<relationship-role-source>
<ejb-name>ProductEJB</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>category</cmr-field-name>
</cmr-field>
</ejb-relationship-role>
</ejb-relation>

</relationships>
<assembly-descriptor>
<security-role>
<role-name>Employees</role-name>
</security-role>
<method-permission>
<role-name>Employees</role-name>
<method>
<ejb-name>CategoryEJB</ejb-name>
<method-name>*</method-name>
</method>
</method-permission>
<container-transaction>
<method>
<ejb-name>CategoryEJB</ejb-name>
<method-name>*</method-name>
</method>
<method>
<ejb-name>ProductEJB</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>

</ejb-jar>

Here is my weblogic-cmp-rdbms-jar.xml:
<!DOCTYPE weblogic-rdbms-jar PUBLIC
'-//BEA Systems, Inc.//DTD WebLogic 8.1.0 EJB RDBMS Persistence//EN'
'http://www.bea.com/servers/wls810/dtd/weblogic-rdbms20-persistence-810.dtd'>
<weblogic-rdbms-jar>

<weblogic-rdbms-bean>
<ejb-name>CategoryEJB</ejb-name>
<data-source-name>ShoeStore</data-source-name>
<table-map>
<table-name>category</table-name>
<field-map>
<cmp-field>categoryId</cmp-field>
<dbms-column>categoryID</dbms-column>
</field-map>
<field-map>
<cmp-field>categoryName</cmp-field>
<dbms-column>categoryName</dbms-column>
</field-map>
<field-map>
<cmp-field>picture</cmp-field>
<dbms-column>Picture</dbms-column>
</field-map>
<field-map>
<cmp-field>pictureWidth</cmp-field>
<dbms-column>PictureWidth</dbms-column>
</field-map>
<field-map>
<cmp-field>pictureHeight</cmp-field>
<dbms-column>PictureHeight</dbms-column>
</field-map>
<field-map>
<cmp-field>labelOn</cmp-field>
<dbms-column>LabelOn</dbms-column>
</field-map>
<field-map>
<cmp-field>labelOff</cmp-field>
<dbms-column>LabelOff</dbms-column>
</field-map>
<field-map>
<cmp-field>button</cmp-field>
<dbms-column>Button</dbms-column>
</field-map>
</table-map>
<automatic-key-generation>
<generator-type>SQL_SERVER</generator-type>

</automatic-key-generation>
</weblogic-rdbms-bean>

<weblogic-rdbms-bean>
<ejb-name>ProductEJB</ejb-name>
<data-source-name>ShoeStore</data-source-name>
<table-map>
<table-name>PRODUCT</table-name>
<field-map>
<cmp-field>productId</cmp-field>
<dbms-column>productId</dbms-column>
</field-map>
<field-map>
<cmp-field>brandName</cmp-field>
<dbms-column>brandName</dbms-column>
</field-map>
<field-map>
<cmp-field>productDescription</cmp-field>
<dbms-column>productDescription</dbms-column>
</field-map>
<field-map>
<cmp-field>purchasePrice</cmp-field>
<dbms-column>purchasePrice</dbms-column>
</field-map>
<field-map>
<cmp-field>category</cmp-field>
<dbms-column>categoryId</dbms-column>
</field-map>
</table-map>

<!-- Automatically generate the value of ID in the database on inserts using sequence table -->
<automatic-key-generation>
<generator-type>SQL_SERVER</generator-type>

</automatic-key-generation>

</weblogic-rdbms-bean>
<weblogic-rdbms-relation>
<relation-name>Category-Product</relation-name>
<weblogic-relationship-role>
<relationship-role-name>Product-belongs-to-Category</relationship-role-name>
<relationship-role-map>
<column-map>
<foreign-key-column>categoryId</foreign-key-column>
<key-column>categoryID</key-column>
</column-map>
</relationship-role-map>
</weblogic-relationship-role>
</weblogic-rdbms-relation>

</weblogic-rdbms-jar>

Here is my productLocal.java:
package com;

import javax.ejb.CreateException;
import javax.naming.NamingException;


import java.util.Date;
import java.util.Vector;
import java.util.Collection;

public interface ProductLocal extends javax.ejb.EJBLocalObject
{
public Integer getProductId();
public void setProductId(Integer productId);

public String getBrandName();
public void setBrandName(String brandName);

public String getProductDescription();
public void setProductDescription(String productDescription);

public Double getPurchasePrice();
public void setPurchasePrice(Double purchasePrice);

public CategoryLocal getCategory();
public void setCategory(CategoryLocal category);
}

Here is my ProductBean.java:
package com;

import javax.naming.InitialContext;
import javax.ejb.EntityContext;
import javax.ejb.CreateException;
import javax.naming.NamingException;
import java.util.Date;
import java.util.Collection;
import java.util.Iterator;
import java.util.Vector;
import java.lang.Integer;
public abstract class ProductBean implements javax.ejb.EntityBean
{
public Integer ejbCreate(Integer id)
{
this.setProductId(id);
return null;
}

public void ejbPostCreate(Integer id)
{

}
//public abstract Integer getCategoryId();
// public abstract void setCategoryId(Integer categoryId);
public abstract CategoryLocal getCategory();
public abstract void setCategory(CategoryLocal category);

public abstract Integer getProductId();
public abstract void setProductId(Integer productId);

public abstract String getBrandName();
public abstract void setBrandName(String brandName);

public abstract String getProductDescription();
public abstract void setProductDescription(String productDescription);

public abstract Double getPurchasePrice();
public abstract void setPurchasePrice(Double purchasePrice);

public void setEntityContext(EntityContext ec)
{
System.out.println("ProductBean setEntityContext");
}
public void unsetEntityContext()
{
System.out.println("ProductBean unsetEntityContext");
}
public void ejbLoad()
{
System.out.println("ProductBean ejbLoad");

}
public void ejbStore()
{
System.out.println("ProductBean ejbStore");
}
public void ejbActivate()
{
System.out.println("ProductBean ejbActivate");

}
public void ejbPassivate()
{
System.out.println("ProductBean ejbPassivate");
}
public void ejbRemove()
{
System.out.println("ProductBean ejbRemove");
}
}

What do I needed to do to fix this problem.

Any hint or help would be greatly appreciated!!!

Yours,

Frustrated
Back to top
Display posts from previous:   
Post new topic   Reply to topic    http://www.roseindia.net Forum Index -> EJB - Enterprise Java Beans All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group