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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:13:01+00:00 2026-05-12T11:13:01+00:00

I have the following POJO: public class SampleBean1 { @Id @GeneratedValue(generator = system-uuid) @GenericGenerator(name

  • 0

I have the following POJO:


public class SampleBean1 {
    @Id
    @GeneratedValue(generator = "system-uuid")
    @GenericGenerator(name = "system-uuid", strategy = "uuid")
    protected String id;

    @OneToOne(cascade=CascadeType.ALL)
    @JoinColumn(name="OneToOneID")
    protected SampleBean1 oneToOne;

    @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY)
    @JoinColumn(name="OneToManyID")
    protected List<SampleBean1> oneToMany;

    @ManyToOne(cascade=CascadeType.ALL)
    @JoinColumn(name="ManyToOneID")
    protected SampleBean1 manyToOne; 

    @ManyToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
    @JoinTable(name="SampleBeanManyToMany",
            joinColumns={@JoinColumn(name="LeftID")},
            inverseJoinColumns={@JoinColumn(name="RightID")})
    @IndexColumn(name="ManyToManyIndex")
    protected List<SampleBean1> manyToMany;

    ...
}

I’m making a library to detect OneToOne or ManyToOne (and doing appropriate operations). It always comes back as ManyToOne.

//Get the class' metadata
ClassMetadata cmd=sf.getClassMetadata(o.getClass());

for(String propertyName:cmd.getPropertyNames()){ org.hibernate.type.Type propertyType=cmd.getPropertyType(propertyName);

//Handle ___ToOne
if (propertyType.isEntityType()){
    EntityType et=(EntityType)propertyType;
    System.out.printf("%s=%s\n",propertyName,et.isOneToOne()?"true":"false");
}

}

Here's what I get back:

manyToOne=false
oneToOne=false

In the debugger the Type of the "oneToOne" is ManyToOneType!! Did I do something wrong or is this a Hibernate defect?

EDIT: Here's how the OneToOne's can work. Let's create three SampleBeans (SB1, SB2, SB3) as described in a comment below. First, the data in POJO form:

SB1.oneToOne=SB2
SB2.oneToOne=SB3
SB3.oneToOne=null

Again the data in database form:

ID|OneToOneID
1|2
2|3
3|null

As long as OneToOneID has a unique constraint, would this type of relation be OneToOne? Is there another way to model OneToOne? Note that the POJO above is intended unidirectional OneToOne. Could that be the issue?

  • 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-12T11:13:01+00:00Added an answer on May 12, 2026 at 11:13 am

    That’s much clearer now, thank you.

    Is it really SampleBean1 in both cases (e.g. entity itself and the OneToOne mapped property) or is it a typo? If they are the same, I’m pretty sure it’s illegal (how do you imagine that mapping would work)? I’m a bit surprised it’s quietly downgraded to “many-to-one” instead of throwing an error, but perhaps that’s what Hibernate Annotations mapper does.

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

Sidebar

Related Questions

Using GWT I have a Java class: public class Pojo { private String name;
I have following foreach-loop: using System.IO; //... if (Directory.Exists(path)) { foreach(string strFile in Directory.GetFiles(path,
I have following classes. class A { public: void fun(); } class B: public
I have following wrapper to help me manage the wcf client lifetime: public class
I have following string String str = replace :) :) with some other string;
I have following table structure: Table: Plant PlantID: Primary Key PlantName: String Table: Party
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
Suppose I have following string: String asd = this is test ass this is
I have the following calls in one of my classes @Override public Integer save(NewsItem
Have following setup: MainActivity class - extends activity MyLayout class - extends View Prefs

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.