0

I am working with Hibernate.

RelationShip Details:

  • One USER belongs to Many COMMUNITY
  • One FACULTY can handle One COMMUNITY
  • FACULTY is a USER

So here FACULTY is a weak entity and I need to create Faculty.java without any primary key attribute like:

private Integer facultyId;

and only with the fields

User user; Community community;

Is there a better way to approach rather than creating facultyId which is redudant here?

Michaël
  • 3,679
  • 7
  • 39
  • 64
schoolcoder
  • 1,546
  • 3
  • 15
  • 31
  • check this http://stackoverflow.com/questions/3820897/jpa-entity-without-id – NPKR Dec 21 '12 at 06:54
  • @Pradeep do you want me to put user and community properties within ? – schoolcoder Dec 21 '12 at 07:04
  • here is some useful link in chech the 'No Primary Key' section http://en.wikibooks.org/wiki/Java_Persistence/Identity_and_Sequencing#No_Primary_Key – NPKR Dec 21 '12 at 07:11

1 Answers1

0

Your relationship details are confusing me:

Practically thinking, If One USER belongs to Many COMMUNITY, One COMMUNITY will definitely have Many USERS. Don't you think SO?? You got to re-think about this..

Still... Considering you defined relationship As long as faculty has no other attributes assigned to it other than community.What I suggest is that instead of creating a separate table for faculty(which I think is not required) you can add extra column in COMMUNITY TABLE as COMMUNITY_ROLE and define role as FACULTY in it for required users. Advantage: Since USER-COMMUNITY are 1 to MANY in relationship, We will have user in COMMUNITY and COMMUNITY_ROLE will define the for FACULTY or NULL.

Still I strongly feel USER-COMMUNITY will be many to many, which will overthrow my workaround solution above which is based on you relationship details provided above which I think are wrong.

DarkHorse
  • 2,740
  • 19
  • 28