• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please Help

 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing Entity bean with CMR having local interfaces.
The employee bean is in relationship with project bean.
The relationship between employee bean and project bean is many to many i.e one employee has many projects and same way one projects has many employee.
I am not able to set relationship so please help me.
The code for employee and project bean is shown below.







Thanks for Help.
 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please help me
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Create methods in both local home are not correct. They should be respectively

Quote:
An entity bean�s local home interface can define zero or more create<METHOD>(...) methods, one for each way to create an entity object. The arguments of the create methods are typically used to initialize the state of the created entity object. The name of each create method starts with the prefix �create�. The return type of a create<METHOD> method on the local home interface is the entity bean�s local interface.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apart from that, could you explain what is not working ? Where do you have difficulties ? The deployment descriptor ?
 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am not able to understand how i will set relationship in ejbPostCreate of
Project bean.
in 1 to 1 and 1 to many examples i used to set relationship in ejbPostCreate method.
I want code that will set relation between Employee bean and Project bean.
I have set relationship in DD successfully.
if i will deploy above code it creates Project table and Employee table but the linking table between Project table and Employee is empty.

Thanks
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would remove the empId from both ejbCreate and ejbPostCreate.
You can set the relation outside the bean :


How did you declare the relationship in your deployment descriptor ?
Here is an example. (FacadeSessionBean is a remote stateless session bean where I have put the above code)

 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Satou
This is code which i use to set relationship


Now if i set following data for emp and proj table
EMP Table
----------
empid=1 name=EMP1
empid=2 name=EMP2
empid=3 name=EMP3
empid=4 name=EMP4


PROJ Table
------------
projid=11 projname=EJBProj
projid=22 projname=JSPProj
projid=33 projname=CoreProj
projid=44 projname=SoapProj

The LInk Table created by container is

EMPID=1 projID=11
EMPID=2 projID=22
EMPID=3 projID=33
EMPID=4 projID=44

In such case i will never able to set many projects to single Employee
because empid is pk for emp table and projId is pk for project table.
thus projId and empid should be unique.

What i want to do is

The LInk Table created by container should be

EMPID=1 projID=11
EMPID=1 projID=22
EMPID=1 projID=33
EMPID=1 projID=44

Above case is single employee(Emp 1) having many project(projid 11,22,33,44);

I hope you understand my problem.

Thanks
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thus projId and empid should be unique.

Yes, for both the project table and the employee table.
But we are talking about the many-to-many relation table, so it's ok. Try


You will see that in the link table, you have :
EMPID=1 projID=11
EMPID=1 projID=22
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm posting my sample, it's not clean, but see what you can do from it.

Client


EmpBean


Project


FacadeSessionBean


Descriptor

[ July 03, 2007: Message edited by: Satou kurinosuke ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I execute the Client, I get the following output :
 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Satou kurinosuke for your help.
Thank you very much.
 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Satou
Can i know which server you are using?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sun's J2EE RI 1.3.1
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic