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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:27:57+00:00 2026-05-26T11:27:57+00:00

I have a situation were I have a class Called Order with a generated

  • 0

I have a situation were I have a class Called Order with a generated OrderID :

    @Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_gen")
@SequenceGenerator(name = "seq_gen", sequenceName = "OID_SEQ1")
@Column(name = "ORDER_ID",nullable = false)
public long getOrderId()
{
    return this.OrderId;
}

it also has a one-to-many mapping with a class/ table called items:

    @OneToMany(fetch = FetchType.LAZY,mappedBy = "orders",targetEntity = Items.class)
public Set<Items> getItems()
{
    return this.items;
}

within the items class is an embedded/composite id:

    @EmbeddedId
@AttributeOverrides({@AttributeOverride(name = "OrderId",column = @Column(name = "ORDER_ID",nullable = false)),
        @AttributeOverride(name = "role",column = @Column(name = "ROLE",nullable = false,length = 10))})
public ItemId getId()
{
    return this.id;
}

My problem is part of this id is the primary key of the parent Order.class. In other words the sequence value. This means I cannot set this value anywhere and when I call:

entitymanager.persist(order);

The parent Order object writes to the db BUT none of the items within the Set are persisted. There is only one insert statement and all the references to orderId in the Items objects are null????

How can I populate these ID’s with the generated Seq ID?

Many thanks for any help with this!

  • 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-26T11:27:58+00:00Added an answer on May 26, 2026 at 11:27 am

    Eventually figured this out with the help of another post:
    onetomany-and-composite-primary-keys
    The answer was in fact quite simple. We need to use the Casade annotation to casade the Id down to the child object. so the one to many mapping above becomes:

    @OneToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY,mappedBy = "orders",targetEntity = Items.class) public Set<Items> getItems() {     return this.items; } 
    

    When implementing this review the different cascade types.

    Good luck

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

Sidebar

Related Questions

Here's the situation. Let's say I have a class called MYFoo. Here's it's initializer:
My situation is essentially this: I have a class called Foo which has dependencies
I have class name called Address in two namespaces. Its been two EDMX files,
In a C++ physics simulation, I have a class called Circle, and Square. These
i have situation like this: class IData { virtual void get() = 0; virtual
I have the following situation: class A { public: A(int whichFoo); int foo1(); int
Pseudo-situation: have a class (let's say BackgroundMagic ), and it has Start() and Stop()
I have the following situation : abstract class X { abstract X someMethod (...)
We have this situation: Window Keyboard ^ ^ | / ApplicationWindow so class Window
I have following situation. In a constructor of a pseudo class I attach a

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.