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.
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.
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.
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)
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.