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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:08:04+00:00 2026-05-17T00:08:04+00:00

I was reading this book. Explaing about @OneToOne unidirectional, the author has taken the

  • 0

I was reading this book. Explaing about “@OneToOne unidirectional”, the author has taken the following Customer, Address example:

@Entity
public class Customer{
   @Id @GeneratedValue
   private Long id;
   private String name;
   private Address address;
   //few other columns, getters/setters
}

@Entity
public class Address{
   @Id @GeneratedValue
   private Long id;
   private String city;
   //few other columns, getters/setters

}

And was saying that –

  • This is the minimum required
    annotaions.
  • No @OneToOne annotaion is
    needed.(Because, by default, the
    persistance provider will assume it)
  • The @JoinColumn annotation allows you
    to customize the mapping of a foreign
    key. As show below, we can RENAME the
    foreign key column to ADD_FK

And then about this one:

@Entity
public class Customer {    
    @Id    @GeneratedValue    
    private Long id;      
    private String name;    
    @OneToOne       
    @JoinColumn(name="ADD_FK")    
    private Address address;    
    //few other    columns, getters/setters 
}

@Entity
public class Order {   
    ....       
    List<OrderLine> orderLines;   
    ... 
}
  • By default, OneToMany relationship is
    assumend when the collection of an
    entity type is being used.

My questions:

  1. Are the above statements Valid? Because when I try these examples on Hibernate, I was getting exceptions.

  2. Does the statements are made as per the JPA
    standards?

  3. Or is it that Hibernate is
    implemented differently?

Kindly clarify.

  • 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-17T00:08:05+00:00Added an answer on May 17, 2026 at 12:08 am

    To my knowledge, relations between entities must be explicitly mapped. From the JPA 1.0 specification (bold is mine):

    2.1.7 Entity Relationships

    Relationships among entities may be
    one-to-one, one-to-many, many-to-one,
    or many-to-many. Relationships are
    polymorphic.

    If there is an association between two
    entities, one of the following
    relationship modeling annotations
    must be applied to the corresponding persistent property or
    field of the referencing entity:
    OneToOne, OneToMany, ManyToOne,
    ManyToMany. For associations that do
    not specify the target type (e.g.,
    where Java generic types are not used
    for collections), it is necessary to
    specify the entity that is the target
    of the relationship.

    (…)

    And this didn’t change in JPA 2.0.

    I thus annotate relationships between entities. And AFAIK, Hibernate will indeed complain about not being able to persist a complex type when not doing so.

    But unless someone can show me the relevant part of the spec, I consider the behavior as correct.

    References

    • JPA 1.0 specification
      • Section 2.1.7 “Entity Relationships”
    • JPA 2.0 specification
      • Section 2.9 “Entity Relationships”
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Reading the Scala by Example book and there is this example when Martin explains
I am reading a book in which author used a code like this public
I'm reading a book about programming ASP.NET in C#. The book makes the following
Currently I'm reading a book (Pro ASP.Net Framework). In this book, the author suggests
I'm reading a book to read and it covers this below example. somelist =
I'm reading a Ruby book but it doesn't explain the following: What is this:
I'm reading this book and there is a chapter about prototypes with this hard
I'm reading page 86 in this book about string and literals and i don't
I'm reading this book on C# and .NET and I'm learning a bunch of
I am reading this book Beginning Java™ EE 6 Platform with GlassFish™ 3: From

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.