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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:34:17+00:00 2026-06-08T17:34:17+00:00

What does mappedBy map to ? Or, rather, what should it map to? The

  • 0

What does mappedBy map to? Or, rather, what should it map to?

The headers field below maps to @Entity Foo as per @OneToMany docs? And then Foo would be a wrapper for javax.mail.Header?

package net.bounceme.dur.usenet.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.mail.Header;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.persistence.*;

@Entity
public class Articles implements Serializable {

    private static final long serialVersionUID = 1L;
    private static final Logger LOG = Logger.getLogger(Articles.class.getName());
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @Column
    private String subject;

    @OneToMany(mappedBy="foo")  //a wrapper for Header is needed?
    private List<Header> headers = new ArrayList<>();

    public Articles() {
    }

    public Articles(Message message) {
        try {
            subject = message.getSubject();
        } catch (MessagingException ex) {
            Logger.getLogger(Articles.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public Long getId() {
        return id;
    }

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

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Articles)) {
            return false;
        }
        Articles other = (Articles) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return subject;
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }
}
  • 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-08T17:34:18+00:00Added an answer on June 8, 2026 at 5:34 pm

    Yes wrapper for javax.mail.Header is needed, in general you cannot persist directly arbitrary classes, especially not the ones that are not Serializable. Also they cannot be elements of list that designs relationship between entities.

    Value of mappedBy is name of the field that is owning side of bidirectional relationship. For a sake of example, let’s assume that Article entity does have one-to-many relationship to Foo entity:

    @OneToMany(mappedBy="article")
    private List<Foo> headers;
    

    Now we know that there must be other end of this relationship, and it is attribute, which is located to Foo entity, does have Article as a type and is named article:

    @Entity
    public class Foo {
    ...
       @ManyToOne
        Article article;
    }
    

    Owning side (in this case article in Foo) is used when bidirectional relationship is persisted to the database. In JPA 2.0 specification this is told with following words:

    Bidirectional relationships between managed entities will be persisted
    based on references held by the owning side of the relationship. It is
    the developer’s responsibility to keep the in-memory references held
    on the owning side and those held on the inverse side consistent with
    each other when they change. In the case of unidirectional one-to-one
    and one-to-many relationships, it is the developer’s responsibility to
    insure that the semantics of the relationships are adhered to.

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

Sidebar

Related Questions

I have two entities like the following: @Entity public class Trip { @OneToMany(mappedBy =
@Entity public class Troop { @OneToMany(mappedBy=troop) public Set<Soldier> getSoldiers() { ... } @Entity public
i have these Pojos: public class ParticipantPojo implements Serializable ..... @OneToMany(mappedBy = participant, cascade
Does the following function cause stack overthrow eventually? var isFinish= false; function foo(){ //
I have defined this Entity class, but it does not seem to save the
class Account { ... /* * @OneToMany(targetEntity=Address, mappedBy=account); */ private $addresses; ... } class
Do you know why this: class Owner { @OneToMany(mappedBy = owner, cascade = CascadeType.ALL)
I have this 2 classes: @Entity public class Student extends User { ... @ManyToMany(mappedBy
Does anyone know if there is a way to generate different code in the
Does COUNT(*) have any significant impact for MySQL performance if query already has GROUP

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.