• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Many to one unidirectional relationship and ejbCreate

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

I am facing problem when creating entity bean. I am using oracle and weblogic server.

I have many to one unidirectional relationship. I hv two tables that i am interested with :

1. Table A

2. Table B.

In Table A, there is a FK refernece to Table B. e.g. CMP field a2 is mapped with b1 field in Table B. Here a2 is not primary key it is just foreing key. From Table A, it is Many to one unidirectional relation ship. In table B, b1 is primary key.

Here i hv CMR Accessor method in Table A and it is unidirectional. As it is many to one relationship exists Accessor methods in A EJB returning me (public B getB()).
When i am trying to call create method on home, it will give me the following errors. Peristance type of entity bean is CMP :

javax.ejb.EJBException: When a cmp-field and a cmr-field (relationship) are mapped to the same column, the setXXX method for the cmp-field may not be called. The cmp-field is read-only.

I have also tried to set that cmr filed in ejbPostCreate, though it' giving me error.

Can anybody hv faced this problem and knowing the solution ?

Thanks in advance,

Dimple sharma
 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Keep in mind the your accessor/mutators in bean A should use the Local Iterface of bean B, and not the bean B itself.

The method you posted, for example


public B getB()



seems to be incorrect.
Of course i don`t what your code looks like, but it shoulb problably be something like



In other words, the return should be beans` B local interface.
 
Ranch Hand
Posts: 977
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


javax.ejb.EJBException: When a cmp-field and a cmr-field (relationship) are mapped to the same column, the setXXX method for the cmp-field may not be called. The cmp-field is read-only.



The problem is well described in the error message you're getting, you're trying to call the setXXX method for the cmp field on the entity bean while it is also mapped for a cmr with other entity bean. You should no call setXXX method on the cmp field under ejb create and then call the setXXX method for the cmr field on the ejbPostCreate. This will solve the problem.

regards.
 
dimple sharma
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

Thanks.


No in ABean i have public abstract B getB();

A and B both are local interface. so obviously B means here local inteface.


I hv tried to set cmp field which mapped in cmr in ejbPostCreate() also, it is giving me the same error.

If any other suggestion u have then plz let me know. I have stucked with this problem.
 
dimple sharma
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Actually i have situation where A is my transaction table having any other key as primary key. Here one field is mapped with master table primary key but as it can be repeated i have only option of having relationship of Many to one, unidirectional. I don't hv any other unique combination in table A, so that i can use any other relation type.

One to one or one to many is not possible as it is not unique key. Many to many is also not possible. If i am using bidirectional relation also then also before creating data how can i get the collection. If it is not allowing me to set one field how can relationship will be build.


I have noted that relationship of one to one or one to many is allowing to set the values. Means if primary key is used in cmr field then it set accessor it is not giving any error. But it is not solving my problem i have many to one relationship.

I don't know if i am only who r using these relationship, how can people handling these type of transaction entries ?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic