• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

CMR relationship prob.

 
Ranch Hand
Posts: 597
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear All,

I am new to EJB and trying to learn CMR relationships


Suppose I have one master table
TABLE NAME : ORDER_HEADER
OrderNo number(5,0) not null,
CustNo number(5,0) not null,
OrderDate Date not null,

constraint pk_order_header primary key ( OrderNo,CustNo,OrderDate)



And Detail Table

TABLE NAME: ORDER_LINE

OrderNo number(5,0) not null,
CustNo number(5,0) not null,
OrderDate Date not null,
LineNo number(5,0) not null,
ItemNo number(5,0)
Qty number(5,0)
Rate number(7,2),
constraint pk_order_detail primary key (OrderNo,CustNo,OrderDate,LineNo),
constraint fk_order_detail_order_header FOREIGN KEY (OrderNo,CustNo,OrderDate) REFERENCES OrderHeader (OrderNo,CustNo,OrderDate)


Now I want write cmr relationship for these two tables using entity beans

which one of following is correct

1)
public abstract class OrderHeaderBean implements EntityBean {
private EntityContext ctx;

/********* CMP ***********/
public abstract Integer getOrderNo();
public abstract void setOrderNo(Integer orderNo);
public abstract Integer getCustNo();
public abstract void setCustNo(Integer custNo);
public abstract long getInvDate();
public abstract void setInvDate(long invDate)


/********* CMR ***********/

public abstract java.util.Collection orderLines getOrderLines();
public abstract void setOrderLines(java.util.Collection orderLines);

............................

...........................


public abstract class OrderLineBean implements EntityBean {
private EntityContext ctx;

/********* CMP ***********/
public abstract Integer getOrderNo();
public abstract void setOrderNo(Integer orderNo);
public abstract Integer getCustNo();
public abstract void setCustNo(Integer custNo);
public abstract long getInvDate();
public abstract void setInvDate(long invDate);
public abstract Integer getLineNo();
public abstract void setLineNo(Integer lineNo);
public abstract Integer getItemNo();
public abstract void setItemNo(Integer itemNo);
public abstract Integer getQty();
public abstract void setQty(Integer qty);
public abstract float getRate();
public abstract void setRate(float rate);



/********* CMR ***********/

public abstract OrderHeaderLocal orderLines getOrderHeader();
public abstract void setOrderHeader(OrderHeaderLocal orderHeader);

.....................
.....................


}


2)
public abstract class OrderHeaderBean implements EntityBean {
private EntityContext ctx;

/********* CMP ***********/
public abstract Integer getOrderNo();
public abstract void setOrderNo(Integer orderNo);
public abstract Integer getCustNo();
public abstract void setCustNo(Integer custNo);
public abstract long getInvDate();
public abstract void setInvDate(long invDate)


/********* CMR ***********/

public abstract java.util.Collection orderLines getOrderLines();
public abstract void setOrderLines(java.util.Collection orderLines);

............................

...........................


public abstract class OrderLineBean implements EntityBean {
private EntityContext ctx;

/********* CMP ***********/
public abstract Integer getLineNo();
public abstract void setLineNo(Integer lineNo);
public abstract Integer getItemNo();
public abstract void setItemNo(Integer itemNo);
public abstract Integer getQty();
public abstract void setQty(Integer qty);
public abstract float getRate();
public abstract void setRate(float rate);

/********* CMR ***********/

public abstract java.util.Collection orderLines getOrderLines();
public abstract void setOrderLines(java.util.Collection orderLines);

............................

...........................
 
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
If you want to hear my suggestion :
simplify you database design, it is horrible.
it is just MHO.
 
Sandeep Awasthi
Ranch Hand
Posts: 597
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Suppose if you are working on maintenance project which is developed in other technology and now is to be redeveloped in n-tier architecture but you are not allowed to change anything in database ( its a fact with me ) then?? and what changes you want me to do in database design ?
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree. Your DB design is not normalized. Your line item table need not refer to customer and order date in line items table. They are part of Order master table and a column like order_id in master table could be referred as foreign key in line items table.

Regarding the methods in beans, it depends on the direction of relationships that exist between order and line items. If you want to know the lineitems for a particular order, then the OrderEJB should have a method to get the getLineItems(..). The method will return you a collection of line items for that particular order.
 
Sandeep Awasthi
Ranch Hand
Posts: 597
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok let me put it in other way.

Suppose I have one table Table_A with composite primary key( column1, column2) I have another table Table_B with composite foregin key (column1,column2) references Table_A(column1,column2).

Now if

EJB_B {
public abstract DATATYPE getColumn1();
public abstract void setColumn1(DATATYPE value);
public abstract DATATYPE getColumn2();
public abstract void setColumn2(DATATYPE value);

public abstract Collection getBs();
public abstract void setBs(Collection Bs)


}

is right or


EJB_B {

public abstract Collection getBs();
public abstract void setBs(Collection Bs)


}
 
Rahul kapoor
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What kind of OO relationship exists between A and B ?
[ October 06, 2004: Message edited by: Rahul kapoor ]
 
Sandeep Awasthi
Ranch Hand
Posts: 597
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont know. Honestly I dont know OO Designs. But have you understood what I am trying to say?
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rajesh Thankare:
Suppose I have one table Table_A with composite primary key( column1, column2) I have another table Table_B with composite foregin key (column1,column2) references Table_A(column1,column2).


So you have a one-to-many relationship (though that could be one-to-one) from A to B. If you want it unidirectional from A to B, then you'll need the following accessors:You also need to create the CustomPK class to hold the two columns. The container, via CMR, will manage the foreign keys in bean B for you -- that's the CM in CMR.
 
Sandeep Awasthi
Ranch Hand
Posts: 597
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do I need to have getter and setter methods for individual columns of Key ( Primary or foreign ) of just getter and setter method for composite primary key and getter and setter methods for CMR is enough ???

Suppose PK is (Column1,Coulmn2),

are these methods necessary ???
public abstract DATATYPE getCloumn1();
public abstract void setColumn1(DATATYPE value);

or

just

public abstract CustomPK getPK();
public abstract void setPK(CustomPK pk);

is enough.
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rajesh Thankare:
Do I need to have getter and setter methods for individual columns of Key ( Primary or foreign ) of just getter and setter method for composite primary key and getter and setter methods for CMR is enough ???


Actually, I believe you need individual field accessors -- not a single PK field accessor. I've never used multi-column PKs in entity beans, though, but when using XDoclet you specify each column in the PK and tag it with @ejb.pk-field.
 
Sandeep Awasthi
Ranch Hand
Posts: 597
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
David Thank you very much for your help.
reply
    Bookmark Topic Watch Topic
  • New Topic