• 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

Is there a problem here ?

 
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all.
I have two entity beans : DeptBean and EmployeeBean.
these two beans are cmp and relation is one to many bidirectional.
the database schema for DeptBean is :
id, description // name is PK
and the schema for EmployeeBean is :
num, name, id // num is PK and id is a FK
I want to deploy them using jboss 3.2 , here is important part of
jbosscmp-jdbc.xml :

my question is, have I configured the beans well ? is there some thing wrong ?
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the code I've made using XDoclet (which I have to reccomend!).

interviewers is like your employee and reqbean is like your department.
The interviewer bean has interviewerId, requisitionId and name.
The req has a lot, but it's pk is "id".



<ejb-relation>
<ejb-relation-name>interviewers-to-reqs</ejb-relation-name>

<foreign-key-mapping/>

<ejb-relationship-role>
<ejb-relationship-role-name>interviewerBean</ejb-relationship-role-name>
<key-fields/>

</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>reqBean</ejb-relationship-role-name>
<key-fields>
<key-field>
<field-name>id</field-name>
<column-name>requisitionId</column-name>
</key-field>
</key-fields>

</ejb-relationship-role>
</ejb-relation>


The XDoclet Code that made this is as follows.

in the interviewer...
/**
* @ejb.interface-method
* @ejb.relation
* name="interviewers-to-reqs"
* role-name="interviewerBean"
* @jboss:relation
* related-pk-field="id"
* fk-column="requisitionId"
*/
public abstract RequisitionLocal getRequisition();
public abstract void setRequisition(RequisitionLocal req);




and in the req
/**
* @ejb.relation
* name="interviewers-to-reqs"
* role-name="reqBean"
*/
public abstract Collection getRequisitionInterviewers();
public abstract void setRequisitionInterviewers(Collection interviewers);


let me know if I help any more.
--Jeff
 
Hussein Baghdadi
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, thank you very much but I have some questions.
1. you have wrote :
* @jboss:relation
* related-pk-field="id"
* fk-column="requisitionId
is the id field is the id of reqBean or interviewerBean ?
fk-column as I think, is the name of field in the table of the database,
so is there a field called requistionId in the table of interviewerBean ?
I think <column-name> element will specify the fk field in the table schema, right ?
2. take a look at these tags :
<ejb-relationship-role-name>reqBean</ejb-relationship-role-name>
<key-fields>
<key-field>
<field-name>id</field-name>
<column-name>requisitionId</column-name>
</key-field>
</key-fields>
and take another one at :
(the following are inside the interviewerBean)
* @jboss:relation
* related-pk-field="id"
* fk-column="requisitionId"
*/
why the id and requistionId are appearing under the reqBean although this bean, has no requistionId field and you specify these information in the interviewerBean ?
3. as a general rule, in the one-many bidirectional relationship , which bean should have the fields of the relation (I mean, inside the jbosscmp-jdbc.xml file) ?
and in our example, the reqBean or the interviewerBean ?
4. I have read the following from a tutorial :
the <field-name> tag must be the primary key field of the entity bean in the relation.
in our example, this bean is the reqBean or interviewer bean ?
Thank you alot and for your help..
 
Jeff Shelley
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. Sorry. id is on the req. requisitionId is the fk in interviewer that points to the reqBean's id.
I've been naming my fields the same as their column names, and it hasn't caused me any grief. id is in the ReqBean, and requisitionId is in the interviewer as the fk to req.
2. This is what I found in the docs regarding where the key-fields stuff goes:
"In a one-to-many relationship, the many side (Gangster in the example) must have an empty key-fields element, and the one side (Organization in the example) must have a key-fields mapping. In one-to-one relationships, one or both roles can have foreign keys."

So it looks like the xml file is correct. I'm not sure why the tags appear to go in the wrong bean. I'll try it the other way and keep you posted.

3. See 2.
4. the field-name is "id" from the reqBean, and column-name has different beharior based on what kind of mapping. For the foreign-key mapping, column-name maps to the fk of the "other" (in this case, interviewer-bean) entity in the relationship.
 
The human mind is a dangerous plaything. This tiny ad is pretty safe:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic