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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:58:49+00:00 2026-05-28T01:58:49+00:00

I am trying to implement a rather complicated mapping in JPA. I need something

  • 0

I am trying to implement a rather complicated mapping in JPA. I need something similar to this example. The There are several kinds of Writers and several kinds of Writings.
Each writing needs to have a persistable author field. It does not matter the dynamic type of the author. This is why I have it set to the Static abstract type.
The authro however should carry two lists, specifying the novels and poems each has written.

I am getting errors saying that I cannot use a MappedSuperClass as the target of a persistable field. Does anyone know how to accomplish what I am trying to accomplish?

I also want the writer to own this bidirectional relationship. so mapped by should be on the Novel or Poem side. However it appears that mapped by can only be on the OneToMany side…. It does not seem like a strange case where one thing owns many things… why can’t i do this…

Thanks very much fopr the help

@MappedSuperclass
@Access(AccessType.PROPERTY)
public abstract class AbstractWriter implements Serializable{

    private Long id;
    private String name;
    private String email;

    private ArrayList<Novel> novels;
    private ArrayList<Poem> poems;


    @OneToMany(mappedBy="author")
    public ArrayList<Novel> getNovels() {
        return novels;
    }
    public void setNovels(ArrayList<Novel> novels) {
        this.novels = novels;
    }

    @OneToMany(mappedBy="author")
    public ArrayList<Poems> getPoems() {
        return poems;
    }
    public void setPoems(ArrayList<Poem> poems) {
        this.poems = poems;
    }

    @Column(nullable=false)
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }

    @Id @GeneratedValue(strategy= GenerationType.AUTO)
    public Long getId() {
        return id;
    }

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


@Entity
public class ProfessionalWriter extends AbstractWriter { 
}

@Entity
public class StudentWriter extends AbstractWriter { 
}


@MappedSuperclass
public abstract class AbstractWriting implements Serializable{

    private Long id;

    private String title;
    private AbstractWriter author;
    private byte[] words;




    @ManyToOne
    public AbstractWriter getAuthor() {
        return author;
    }
    public void setAuthor(AbstractWriter author) {
        this.author = author;
    }

    @Id @GeneratedValue(strategy= GenerationType.AUTO)
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }

    @Lob
    public byte[] getWords() {
        return words;
    }
    public void setWords(byte[] words) {
        this.words = words;
    }

    @Column(nullable=false)
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
}

@Entity
public class Novel extends AbstractWriting {
}

@Entity
public class Poem extends AbstractWriting {
}
  • 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-28T01:58:49+00:00Added an answer on May 28, 2026 at 1:58 am

    The abstract classes should be annotated with @Entity, rather than @MappedSuperclass. And you should of course choose an inheritance strategy.

    Regarding the owning side: owning an association doesn’t have any semantic meaning. It just means that it’s this side of the association that is used by JPA to know if the association exists. JPA indeed mandates that the many side owns the association mapping, whic is logical since it’s in the table associated to the many side that the foreign key is. For you, it just means that when a poem is added to an author, this poem should reference its author, because that’s what will make the association persistent.

    Also, you should not use ArrayList, but List. EclipseLink will use its own List implementation to support lazy-loading, cascades, etc. And BTW, it’s good practice to program to interfaces rather than implementations.

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

Sidebar

Related Questions

Using PHP, and MySql, I am trying to implement this rather snazzy in-place editor
All I am currently trying implement something along the lines of dim l_stuff as
Trying to implement a UITableView of names similar to the built-in Contacts iPhone app
While trying to implement an MVC file upload example on Scott Hanselman's blog. I
I am trying to implement Ext.ux.grid.filter.ListFilter using a data store (rather than a hardcoded
I am trying to implement a search algorithm in my simple datastructure. However, this
I'm trying to implement swiftmailer into this mailing system. my client has about 300k
I'm trying to implement a rather large object that implements many interfaces. Some of
I am trying to implement a gallery which always starts from left rather than
I am trying to implement the Facebook Like button on my site, but rather

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.