Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

How do we update relationship data using CMP model entity bean ??

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey All,

Another one of my problems.

I am developing entity beans ( EJB 2.0 spec ) using CMP Model in weblogic 8.1 SP4 version. I have defined two tables that have a relationship and the deployment descriptor does have entry for them and their relationship.

I got an object from database using findByPrimaryKey. I tried to update values in table A ( that i called ) and it seems to work fine. When i tried to set the value for the table B , i get an exception,

The setXXX method for a cmr-field that is mapped to a primary key may not be called. The cmr-field is read-only.

But i do not have it defined as ReadOnly, i have it as database in Concurrency-Strategy..

Am i doing anything wrong OR i should call the table B's findByPrimaryKey to make the updates ???

All suggestions are welcome
 
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
customerBean - > addressBean
(CMR Field : address on customerBean)

create table customer(
customer_id
address_id
)

create table address(
address_id,
customer_id
)

cust.getAddress() //allowed
cust.setAddress(AddressLocal addrLocal)//allowed
cust.getAddressid() //allowed
cust.setAddressId(addressId) //Not allowed

I'm not sure if you trying to do this.
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Mohen Vijay:
Hey All,

I got an object from database using findByPrimaryKey. I tried to update values in table A ( that i called ) and it seems to work fine. When i tried to set the value for the table B , i get an exception,



are you doing

(where A & B are the beans.)

A a = AHome.findByPrimKey();
a.setFoo(foo);
a.setBar(bar);

and then


a.getB().setBoo("boo") ??

If this is the case then this statement should work.
 
Vicky Mohan
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The example you have pointed out is for 1- 1 relationship ..

I have an table A that can be related to multiple entries in table B .

If AA is the primary key in table A, table B has a primary-key call ( combination of two columns, one of which is AA and another one CC,which is a primary key in table C, that we are not concerned about right now .

Example -- .

I call the findByPrimaryKey of table A
By the relation with the table B , i get the collection of localObjects from table B...

Now, if i want to update the changed values in table B, i try to set in the values like this

tableBLocal.settableBCollections(Collection_tableBItems) --

I get the exception when i try to update the new line items

javax.ejb.EJBException: [EJB:010146]The setXXX method for a cmr-field that is mapped to a primary key may not be called. The cmr-field is read-only.

Is there anything more i need to specify in deployment descriptors .

I am thinking relationship is fine, because i am eager loading the data and it seems to be working fine.

Also, is there anything i need to do in the ejbCreate() or ejbPostCreate()???

ejb-jar.xml


<ejb-relation>
<ejb-relation-name>GrieveNatureChecklist - GrievanceEJB</ejb-relation-name>
<ejb-relationship-role>
<ejb-relationship-role-name>GrieveNatureChecklist has one GrievanceEJB</ejb-relationship-role-name>
<multiplicity>Many</multiplicity>
<relationship-role-source>
<ejb-name>GrieveNatureChecklist</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>grievanceEJB_grieveSeqId</cmr-field-name>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>GrievanceEJB may have many GrieveNatureChecklist</ejb-relationship-role-name>
<multiplicity>One</multiplicity>
<relationship-role-source>
<ejb-name>GrievanceEJB</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>grieveNatureChecklist_grieveSeqId</cmr-field-name>
<cmr-field-type>java.util.Collection</cmr-field-type>
</cmr-field>
</ejb-relationship-role>
</ejb-relation>



weblogic-cmp-rdbms-jar.xml



<relation-name>GrieveNatureChecklist - GrievanceEJB</relation-name>
<weblogic-relationship-role>
<relationship-role-name>GrieveNatureChecklist has one GrievanceEJB</relationship-role-name>
<relationship-role-map>
<column-map>
<foreign-key-column>GRIEVE_SEQ_ID</foreign-key-column>
<key-column>GRIEVE_SEQ_ID</key-column>
</column-map>
</relationship-role-map>
</weblogic-relationship-role>
</weblogic-rdbms-relation>


GrievanceLocalHome home = (GrievanceLocalHome)EJBHomeFactory.getEJBLocalHome("GrievanceEJBLocal");

GrievanceLocal grievanceLocal = (GrievanceLocal)home.findByGrievanceId(new Long("1050"));

grievanceLocal.setResponseDate(timeStamp);


above code works fine

Collection grieveNatureCheckList = grievanceLocal.getGrieveNatureChecklist_grieveSeqId();

grievanceLocal.setGrieveNatureChecklist_grieveSeqId(grieveNatureCheckList);

above code causes exception and fails .

Any Suggestions
[ January 27, 2005: Message edited by: Mohen Vijay ]
    Bookmark Topic Watch Topic
  • New Topic