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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:05:03+00:00 2026-06-05T09:05:03+00:00

I have two entities: Corpus entity: @Entity(name = CORPUS) public class Corpus implements Serializable

  • 0

I have two entities:

Corpus entity:

@Entity(name = "CORPUS")
public class Corpus implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID")
    private Long id;

    @OneToMany(mappedBy = "corpus", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private Collection<CorpusHistory> corpusHistories;

    //Setters and getters...
}

Corpus history entity:

@Entity(name = "CORPUS_HISTORY")
public class CorpusHistory implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "ID")
    private Long id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name="CORPUS_ID")
    private Corpus corpus;

    //Setters and getters...
}

The corpus entity can have many records of corpus history so I am annotating it with @OneToMany. I want the mapping to be done using the corpus id so I am using @JoinColumn(name="CORPUS_ID") and @ManyToOne annotation in corpus history entity.

Before persisting the corpus object to database I set the corpus history collection to it:

LinkedList<CorpusHistory> corpusHistories = new LinkedList<CorpusHistory>();
for (Change change : changes) {
    CorpusHistory corpusHistory = new CorpusHistory();
    //corpusHistory.setCorpusId(String.valueOf(corpusId)); ?????
    corpusHistory.setRevisionAuthor(change.getName());
    corpusHistory.setRevisionDate(change.getWhen());
    corpusHistory.setRevisionNote(change.getNote());
    //corpusHistoryFacade.create(corpusHistory);
    corpusHistories.add(corpusHistory);
}

corpus.setCorpusHistories(corpusHistories);

Records are created all it is ok but in the corpus history table the CORPUS_ID column is always null. And when I am retrieving corpus from database the history list is empty. I do not understand how can I specify the corpus id to corpus history if the corpus record is not created yet?

Isn’t this an EJB job to do? With @OneToMany and @ManyToOne mapping the appropriate ID’s should be mapped and stored into appropriate columns (in this case the corpus id should be stored in every record of corpus history column CORPUS_ID).

Or I am misunderstanding something here? I have tried many tutorials, no success… I am stuck here.

  • 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-05T09:05:05+00:00Added an answer on June 5, 2026 at 9:05 am
    for (Change change : changes) {
        CorpusHistory corpusHistory = new CorpusHistory();
        corpusHistory.setCorpus(corpus);
        ...
    }
    

    The owner side is the one without the mappedBy attribute. You must initialize the owner side in order to tell JPA that the association exists. Since you have a cascade on corpus.histories, when you persist the corpus, JPA will also persist the histories.

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

Sidebar

Related Questions

I have two entities User and Group: @Entity public class User implements Serializable {
I have two entities A and B: A.java: ... public class A implements Serializable
I have two entities: Event and Comment. @Entity @Table(name = events) public class Event
A have two entities. For example timing settings and orders. @Entity public class TimingSettings{
I have two entities like the following: @Entity public class Trip { @OneToMany(mappedBy =
I have two entities @Entity public class Tabulka{ @OneToMany(mappedBy = tabulka) private List<VysledkyHraca> vysledkyHraca;
I have two entities Room.php /** * @ORM\Table(name=room) * @ORM\Entity(repositoryClass=Ahsio\StackBundle\Repository\RoomRepository) */ class Room {
I have two entities A and B. public class A{ @Id @GeneratedValue private Integer
I have two entities: public class Parent() { public ICollection<Child> Children { get; set;
I have two entities that are something like that: public class Movie { public

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.