Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8031605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:09:30+00:00 2026-06-05T01:09:30+00:00

i have 3 tables: Playlist , Advertisement , PlaylistadMap (Join Table) 1- PlayList :

  • 0

i have 3 tables: Playlist , Advertisement , PlaylistadMap (Join Table)

1- PlayList:

@Entity
@Table(name = "playlist", catalog = "advertisedb")
public class Playlist implements java.io.Serializable {


    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    private Set<PlaylistadMap> PlaylistadMaps = new HashSet<PlaylistadMap>(0);

}

2- Advertisement:

@Entity
@Table(name = "advertisement", catalog = "advertisedb")
public class Advertisement implements java.io.Serializable {


    @OneToMany(fetch = FetchType.LAZY, mappedBy = "advertisement")
    private Set<PlaylistadMap> PlaylistadMaps = new HashSet<PlaylistadMap>(0);

}

3- PlaylistadMap:

@Entity
@Table(name = "playlist_ad_map", catalog = "advertisedb")
public class PlaylistadMap implements java.io.Serializable {


    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "fk_advertisement", referencedColumnName = "pkid", nullable = false)
    private Advertisement advertisement;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "fk_playlist", referencedColumnName = "pkid", nullable = false)
    private Playlist playlist;

}

lets suppose that the playlist 1 has 3 related ads in the database:

(1,1)(1,2)(1,3)
if i am trying to add 3 more ads to the old ones
so the list to be updated will contain (1,1)(1,2)(1,3) (1,4)(1,5)(1,6)
the records in the DB will be:

(1,1)(1,2)(1,3) (1,1)(1,2)(1,3)(1,4)(1,5)(1,6)

do i have to remove the duplicate records manually by deleting all records then insert the new ones ? or there’s a solution in hibernate for this issue.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T01:09:32+00:00Added an answer on June 5, 2026 at 1:09 am

    Your mapping is wrong: you defined two different associations between Playlist and PlaylistadMap instead of a single bidirectional one, because you forgot the mappedBy attribute in PlayList.

    And no, you don’t have to remove and re-add the existing ads to the set. It wouldn’t change anything. Just add your 3 new ads to the set, make sure the other side of the association is initialized correctly, and everything should be fine.

    Also note that cascading is not related to your problem. Cascading means: when I do X on an entity, also do X on the associated entities. You’re just creating an association between entities here. There’s nothing to cascade.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tables linked by FK, I query on the first table using entity
I have a DOM structure like the following: <table class=playlist> <thead> <tr> <th>TH1</th> <th
I have tables Product ( ID, CategoryID, ... ) Category ( ID, Name, ..
hi i have tables like this: Persons: person_id, name then i have many langauge
I have three tables A: A.pID primary key, A.Name nvarchar(250) B: B.pID primary key,
I have 5 tables: customers id - name p_orders id - id_customer - code
I have a three tables for my wordpress plugin. videos = id, name playlists
I have tables: Teachers and Students. We have a SpecialProjects Table where Teachers and
I have two tables, say Table A and Table B. I want to have
Suppose i have tables Products -------product_id , name , price , size shopping_cart------cart_id,item_id,user_id,quantity order----order_id

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.