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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:58:10+00:00 2026-05-31T19:58:10+00:00

I am new to JPA and have some problems in understanding bidirectional relations. I

  • 0

I am new to JPA and have some problems in understanding bidirectional relations.

I have the entities Job and Execution. 1 Job belongs to exactly 1 Execution and vice versa. So, I wanted to use the onetoone relation.

My code looks like following:

@Entity
public class Execution {
        ....
       @OneToOne(cascade=CascadeType.ALL,optional=false)
        private Job job;
        ....
}

@Entity
public class Job{
    ......
   @OneToOne(mappedBy="job",optional=false)
    private Execution execution;
    .....
 }

I set optional=false for both fields. As expected, hibernate throws an exception if I try to persist an Execution object which has a Null Job object.
But persisting a Job object with a Null Execution object is possible, although I set optional=false.

What am I doing wrong?

  • 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-31T19:58:12+00:00Added an answer on May 31, 2026 at 7:58 pm

    Try adding the following annotation.

    @Column(nullable = false)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im new in hibernate and JPA and i have some problems with annotations. My
I am having trouble setting up jpa mappings for some entities. I have a
Assume we have following JPA Entities: class Parent { @Id private Long id; }
In JPA the Entities are nice annotated Plain Old Java Objects. But I have
I'm pretty new to JPA/JDO and the whole objectdb world. I have an entity
I am new to JPA. So my question should be so simple to some.
I am new to JPA & Hibernate. After reading some online materials I now
I have an JEE5 app using EJB3 with JPA. E.g I have some beans
I have a JSF project working with JPA, I do this : retrive some
I am new to JPA, I used to used prepared statement in JDBC. Is

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.