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 4343570
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:46:21+00:00 2026-05-21T11:46:21+00:00

I am developing an application to help my office track and manage reviews. In

  • 0

I am developing an application to help my office track and manage reviews. In the application, I am using JPA 2.0 with Hibernate 3.6.3 as my underlying provider. I am also using spring to inject the persistence context into my DAO. I have built the domain such that there is a Review, a Participant and a Role Entity.

The problem I am having is when I get a Review from the Entity Manager there are duplicate copies of the same Participant(i.e. same ID) in the list of participants if the Participant has more than one Role. I have also found the number of duplicates is directly related to the number Roles (i.e. if the a Participant has 3 Roles then the Participant occurs 3 times in the Review’s list of participants)

I have used straight Hibernate before but this is my first time using JPA so I am sure I have configured something wrong. I just don’t know what it is.

Here is the code:

Review:

@Entity
public class Review extends BaseModel{

@ManyToOne(cascade=CascadeType.ALL, fetch=FetchType.EAGER, optional=false)
private Item item;

@Column(name="ISNEW", nullable=false)
private boolean isNew;

@Enumerated(EnumType.STRING)
@Column(name="STATUS", nullable=false)
private ReviewStatus status;

@Enumerated(EnumType.STRING)
@Column(name="PHASE", nullable=false)
private Phase phase;

@Enumerated(EnumType.STRING)
@Column(name="REVIEW_TYPE", nullable=false)
private ReviewType reviewType;

@OneToMany( cascade=CascadeType.ALL, fetch=FetchType.EAGER)
private List<Participant> participants;

@OneToMany(cascade=CascadeType.ALL)
private List<Defect> defects;

@Column(name="START_DATE", nullable=false)
private Date startDate;

@Column(name="MEETING_DATE", nullable=false)
private Date meetingDate;

@Column(name="FINISH_DATE")
private Date finishDate;

@Column(name="DURATION", nullable=false)
private Double duration;

public Item getItem()
{
    return item;
}
public void setItem(Item item)
{
    this.item = item;
}   
public List<Participant> getParticipants() {
    return participants;
}
public void setParticipants(List<Participant> participants) {
    this.participants = participants;
}
public List<Defect> getDefects() {
    return defects;
}
public void setDefects(List<Defect> defects) {
    this.defects = defects;
}   
public boolean isNew() {
    return isNew;
}
public void setNew(boolean isNew) {
    this.isNew = isNew;
}
public Phase getPhase() {
    return phase;
}
public void setPhase(Phase phase) {
    this.phase = phase;
}
public Double getDuration() {
    return duration;
}
public void setDuration(Double duration) {
    this.duration = duration;
}
public ReviewStatus getStatus() {
    return status;
}
public void setStatus(ReviewStatus status) {
    this.status = status;
}
public Date getStartDate() {
    return startDate;
}
public void setStartDate(Date startDate) {
    this.startDate = startDate;
}
public Date getMeetingDate() {
    return meetingDate;
}
public void setMeetingDate(Date meetingDate) {
    this.meetingDate = meetingDate;
}
public Date getFinishDate() {
    return finishDate;
}
public void setFinishDate(Date finishDate) {
    this.finishDate = finishDate;
}
public ReviewType getReviewType()
{
    return reviewType;
}
public void setReviewType(ReviewType reviewType)
{
    this.reviewType = reviewType;
}

}

Participant:

@Entity
public class Participant extends BaseModel{


        private Double inspectionTime;

        @ManyToOne(cascade=CascadeType.ALL, optional=false)
        private Person person;

        @ManyToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER )
        private Set<Role> roles;

        public Double getInspectionTime() {
            return inspectionTime;
        }
        public void setInspectionTime(Double preInspectionTime) {
            this.inspectionTime = preInspectionTime;
        }
        public Person getPerson() {
            return person;
        }
        public void setPerson(Person person) {
            this.person = person;
        }
        public Set<Role> getRoles() {
            return roles;
        }
        public void setRoles(Set<Role> roles) {
            this.roles = roles;
        }

}

Role:

@Entity
public class Role extends BaseModel{
            @Column(nullable=false, unique=true)
            private String name;
            private String responsiblity;

            public String getName() {
                return name;
            }
            public void setName(String name) {
                this.name = name;
            }
            public String getResponsiblity() {
                return responsiblity;
            }
            public void setResponsiblity(String responsiblity) {
                this.responsiblity = responsiblity;
            }

}

Base:

@MappedSuperclass
public abstract class BaseModel {

    @Id
    @GeneratedValue
    private Long id;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }   

}

DataAccessObject which uses the entityManager:

@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
public class ReviewDaoJpaImpl implements ReviewDao
{


    @PersistenceContext
    private EntityManager em;

    public Review getReviewById(Long id)
    {
        return em.find(Review.class, id);
    }
}

Call which receives duplicates:

    Review review = reviewDao.getReviewById(1776L);
    List<Participant> participants = review.getParticipants();
    for (Participant participant : participants)
    {
        System.out.println(participant.getPerson().getName());
    }
  • 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-05-21T11:46:21+00:00Added an answer on May 21, 2026 at 11:46 am

    The problem is called (N+1 Problem) and is related to the eager fetch of Roles in Participant.

    The easiest way the handle it would be replacing the eager fetch by lazy loading.

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

Sidebar

Related Questions

I am currently developing a little ecommerce application to help me get to grips
I'm developing application using backbone.js & jquery. I have following code in model: runReport:
What is difference in developing applications using .Net Framework, Asp.net and developing application in
I am not much familiar with developing application using cocoa on mac. Can some
Developing iphone application using makkit framework. I have got the map view integrated in
I am developing an application on the Google App Engine using Python (and Django,
I am developing an application in WPF in .NET 3.5. I need help on
i am developing one application related to graphics, in this application i am using
i am developing an application using c#.net in which i need that if a
I'm currently developing an application to help scanning and showing images here at my

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.