Link to home
Start Free TrialLog in
Avatar of ldbkutty
ldbkuttyFlag for India

asked on

Creating Entity bean for a 'table' without PrimaryKey

Hi,

I have a relation table without primarykey. My table name is "favorite" and it has:
worker_id   int   (FK to "worker" table)
task_id   int   (FK to "tasks" table)
priority   int

If i want to create an Entity Bean, we usually create all the 'columns' with getter and setter along with the column type. For example, (just an example):
           
     /**
       * @author bj 17.09.2004
       * Name
       *
       * @ejb.interface-method view-type = "both"
       * @ejb.persistence column-name = "name"
       * @return
       */
      public abstract String getName();

      /**
       * @ejb.interface-method view-type = "both"
       * @param name
       */
      public abstract void setName(String name);


The method ejbCreate() should have the return type of PrimaryKey. My every other table has a PK field and i do like:
     public Integer ejbCreate() throws CreateException {
            return null;
    }

Since my "Favorite" table doesn't have a PK field, how can i create en Entity bean for that table? How to solve the problem of ejbCreate() return type?
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

It does have a primary key.  The primary key is a composite of:

  worker_id and task_id

isn't it?

Have a look at this:  http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/CMP8.html (for CMP) and this http://java.sun.com/j2ee/1.4/docs/tutorial/doc/BMP4.html (for BMP)

Avatar of ldbkutty

ASKER

I understand that PK is combination of worker_id and task_id, but i cannot/shouldn't  create the FK fields(getter, setter) in my Entity Bean. Instead I have to make the relation for those FK's.

For example, in my "Tasks" table, i have 'taskworker_id' FK column to "TaskWorker" table. In my Entity bean, i have:

     /**
       * @author bj 16.09.2004
       *
       * Task TaskWorker Relation
       *
       * @ejb.interface-method
       *       view-type = "local"
       *
       * @ejb.relation
       *       name = "taskworker_task"
       *          role-name = "task from taskworker"
       *
       * @jboss.relation
       *       fk-column = "'taskworker_id"
       *       related-pk-field = "id"
       *       fk-constraint = "true"
       */
      public abstract TaskWorkerLocal getTaskWorker();

      /**
       * @ejb.interface-method view-type = "local"
       * @param taskWorker
       */
      public abstract void setTaskWorker(TaskWorkerLocal taskWorker);
ASKER CERTIFIED SOLUTION
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>     public FavouritePK ejbCreate( Worker w, Task t )

should be

    public FavouritePK ejbCreate( Worker w, Task t, int priority )
sorry for late...but that worked great.

Thanks.
:-)  Cool :-)

Good luck with it :-)

Tim