Difference Between One-to-Many, Many-to-One and Many-to-Many?

后端 未结 8 2049
孤城傲影
孤城傲影 2020-11-28 17:39

Ok so this is probably a trivial question but I\'m having trouble visualizing and understanding the differences and when to use each. I\'m also a little unclear as to how co

8条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-28 17:46

    this would probably call for a many-to-many relation ship as follows

    
    
    public class Person{
    
        private Long personId;
        @manytomany
    
        private Set skills;
        //Getters and setters
    }
    
    public class Skill{
        private Long skillId;
        private String skillName;
        @manyToMany(MappedBy="skills,targetClass="Person")
        private Set persons; // (people would not be a good convenion)
        //Getters and setters
    }
    
    

    you may need to define a joinTable + JoinColumn but it will possible work also without...

提交回复
热议问题