Results 1 to 7 of 7
  1. #1
    voipp is offline Member
    Join Date
    Oct 2013
    Posts
    51
    Rep Power
    0

    Default Many-to-many with extra columns

    Hi!
    I have mapping like :

    Java Code:
    @Entity
    @Table(name = "exit_codes")
    public class ExitCodesEntity {
    
        private Integer exitId;
        private String  description;
        private Set<LaunchesHistoryEntity> launchesHistoryEntities = new
                HashSet<LaunchesHistoryEntity>(0);
    
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        @Column(name = "exit_id", unique = true, nullable = false)
        public Integer getExitId() {
            return exitId;
        }
    
        public void setExitId(Integer exitId) {
            this.exitId = exitId;
        }
    
        @OneToMany(mappedBy = "exitCodesEntity")
        public Set<LaunchesHistoryEntity> getLaunchesHistoryEntities() {
            return launchesHistoryEntities;
        }
    
        public void setLaunchesHistoryEntities(Set<LaunchesHistoryEntity> launchesHistoryEntities) {
            this.launchesHistoryEntities = launchesHistoryEntities;
        }
    
    //..... etc
    
    }
    and

    Java Code:
    @Entity
    @Table(name = "launches")
    public class LaunchesEntity {
        private int                         launchId;
        private String                      dateStart;
        private String                      dateEnd;
        private String                      status;
        private String                      dateQuery;
        private List<LaunchesHistoryEntity> launchesHistoryEntities;
    
        @Column(name = "template_id")
        public Integer getTemplateId() {
            return templateId;
        }
    
        public void setTemplateId(Integer templateId) {
            this.templateId = templateId;
        }
    
        private Integer templateId;
    
        @OneToMany(mappedBy = "launchesEntity")
        public List<LaunchesHistoryEntity> getLaunchesHistoryEntities() {
            return launchesHistoryEntities;
        }
    
        public void setLaunchesHistoryEntities(List<LaunchesHistoryEntity> launchesHistoryEntities) {
            this.launchesHistoryEntities = launchesHistoryEntities;
        }
    
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        @javax.persistence.Column(name = "launch_id")
        @Id
        public int getLaunchId() {
            return launchId;
        }
    
        public void setLaunchId(int launchId) {
            this.launchId = launchId;
        }
    
    
    
    //..... etc
    }
    and Join table :

    Java Code:
    @Entity
    @Table(name = "launch_history")
    public class LaunchesHistoryEntity {
    
        private Integer         Id;
        private ExitCodesEntity exitCodesEntity;
        private LaunchesEntity  launchesEntity;
    
        @ManyToOne
        @JoinColumn(name = "launch_id")
        public LaunchesEntity getLaunchesEntity() {
            return launchesEntity;
        }
    
        public void setLaunchesEntity(LaunchesEntity launchesEntity) {
            this.launchesEntity = launchesEntity;
        }
    
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        public Integer getId() {
            return Id;
        }
    
        public void setId(Integer id) {
            Id = id;
        }
    
        @ManyToOne
        @JoinColumn(name = "exit_code")
        public ExitCodesEntity getExitCodesEntity() {
            return exitCodesEntity;
        }
    
        public void setExitCodesEntity(ExitCodesEntity exitCodesEntity) {
            this.exitCodesEntity = exitCodesEntity;
        }
    }
    and , at the end, the database schema :
    Many-to-many with extra columns-.png

    So my question is : what are advantages and disadvantages between my many-to-many POJO-classes structure and my-kyong structure (with embeddable classes):

    Hibernate – Many-to-Many example – join table + extra column (Annotation)

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,870
    Rep Power
    5

    Default Re: Many-to-many with extra columns

    "between my many-to-many POJO-classes structure"

    Are you now referring to previous posts you have made an expect us to remember exactly what code you posted back there, or am I just not understanding you correctly? I see only one structure here, yet you speak of two.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    voipp is offline Member
    Join Date
    Oct 2013
    Posts
    51
    Rep Power
    0

    Default Re: Many-to-many with extra columns

    Quote Originally Posted by gimbal2 View Post
    "between my many-to-many POJO-classes structure"

    Are you now referring to previous posts you have made an expect us to remember exactly what code you posted back there, or am I just not understanding you correctly? I see only one structure here, yet you speak of two.
    The first structure(i mentioned it as "my many-to-many POJO-classes structure") you can see above in the first message of the post. The second structure you can see clicking the link in the first message, lol.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,945
    Rep Power
    19

    Default Re: Many-to-many with extra columns

    How is that structure any different in any meaningful way?

    Apart from the (in your case) unnecessary "id" column on the join table.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    voipp is offline Member
    Join Date
    Oct 2013
    Posts
    51
    Rep Power
    0

    Default Re: Many-to-many with extra columns

    Quote Originally Posted by Tolls View Post
    How is that structure any different in any meaningful way?

    Apart from the (in your case) unnecessary "id" column on the join table.
    No difference in meaningful way, but in syntax way. Thats why i have posted the question!

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,870
    Rep Power
    5

    Default Re: Many-to-many with extra columns

    Well if you make the effort to setup an actual comparison between the two methods inside this thread in stead of just lazily linking to an external site and expecting people to invest a good amount of time into trying to figure out what is spooking around inside your head, then I may consider thinking about it.

    oh before I forget: lol!
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,945
    Rep Power
    19

    Default Re: Many-to-many with extra columns

    Quote Originally Posted by voipp View Post
    No difference in meaningful way, but in syntax way. Thats why i have posted the question!
    Oh hang on...the composite primary key.
    Well, that's good DB design.
    It's a join table, so shouldn't have it's own id...it's primary key is the two id's it's linking together.

    Bit gimbal's right. You should have explained better what exactly it is that you're asking about, and not simply post two things and ask "which is better". Especially when one thing is to an external site.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Extra functionality?
    By CruelCoin in forum New To Java
    Replies: 3
    Last Post: 12-18-2013, 04:41 PM
  2. Replies: 2
    Last Post: 11-30-2011, 02:08 PM
  3. Extra bracket
    By CrazyShells Slam in forum New To Java
    Replies: 5
    Last Post: 05-16-2008, 06:12 AM

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
  •