Results 1 to 3 of 3

Thread: ManyToMany with interfaces

  1. #1
    Join Date
    Dec 2010
    Posts
    26

    Default ManyToMany with interfaces

    Hi

    I have an application in which I have 4 entities User, Group, Message and Ticket each entity has an id that is being generated by their corresponding sequences. I'm using JPA with Hibernate.

    Code:
    @Entity
    class User extends SomeClassA{
         @Id
         @GeneratedValue(generator="seqUser")
         int userId;
         ... other fields, getter and setters ....
    }
    
    @Entity
    class Group extends SomeClassB{
         @Id
         @GeneratedValue(generator="seqGrp")
         int groupId;
         ... other fields, getter and setters ....
    }
    @Entity
    class Message extends SomeClassC{
         @Id
         @GeneratedValue(generator="seqMsg")
         int msgId;
         ... other fields, getter and setters ....
    }
    @Entity
    class Ticket extends SomeClassD{
         @Id
         @GeneratedValue(generator="seqTic")
         int ticId;
         ... other fields, getter and setters ....
    }
    The application is working fine. Now I need to make few changes in this application:
    1. Each Message and Ticket needs to be approved.
    2. There can be multiple approvers for each Message/Ticket.
    3. Each User/Group will have an approval queue.

    I've thought of implementing the changes as follows:
    1. User and Group will implement interface 'Approver'.
    2. Message and Ticket will implement interface 'Approvable'.
    3. User and Group will have a List<Approvable> approvalQueue;
    4. Message and Ticket will have a List<Approver> approvers;

    Can anyone help me understand how this can be done?

    Thanks
    Amit Khanna
    Last edited by amitkhanna; Aug 17th, 2011 at 08:11 AM.

  2. #2
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default

    Hello

    A POJO/Entity class should represent only a noun without an action or verb, therefore is not wise, and I never have seen a POJO/Entity implementing some interface, you are mixing concers

    such logic must be located in some Service/BO class
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  3. #3
    Join Date
    Dec 2010
    Posts
    26

    Default

    Thanks for your reply. I understand that what i'm trying is wrong. Can you suggest a better way of implementing the three changes I mentioned:

    1. Each Message and Ticket needs to be approved.
    2. There can be multiple approvers for each Message/Ticket.
    3. Each User/Group will have an approval queue.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •