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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:17:47+00:00 2026-06-11T03:17:47+00:00

I wanted to create bidirectional one to one relationship with shared primary key. As

  • 0

I wanted to create bidirectional one to one relationship with shared primary key.

As it is stated here JPA Hibernate One-to-One relationship I have:

@Entity
public class UserProfileInformation {

    @Id
    @GeneratedValue(generator = "customForeignGenerator")
    @org.hibernate.annotations.GenericGenerator(
        name = "customForeignGenerator",
        strategy = "foreign",
        parameters = @Parameter(name = "property", value = "userEntity")
    )
    long id;

    private long itemsPerPage;

    @OneToOne(mappedBy="userProfileInformation")
    private UserEntity userEntity;
...}

@Entity
@Table(name = "UserTable")
public class UserEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    private String publicName;

    private String password;

    private String emailAddress;

    private String name; 

    private boolean active;

    @OneToOne(cascade=CascadeType.ALL)
    @PrimaryKeyJoinColumn
    private UserProfileInformation userProfileInformation;
...}

now, when I try to persist my user in the database, I am getting org.hibernate.id.IdentifierGenerationException: null id generated for:class pl.meble.taboret.model.UserProfileInformation. Is it because, when userProfileInformation is persisted to the database userEntity doesn’t have id generated at that point?

Also, what can I do to create bidirectional relationship with shared primary key in my example?

EDIT:
Requested code, this is simple controller to test the operation of persisting UserEntity.

@Controller
@RequestMapping("/test")
public class TestController {
    @Autowired
    UserDao userDao;

    @RequestMapping(method= RequestMethod.GET)
    public String t(Model model){
        UserEntity entity=new UserEntity();
        entity.setActive(false);
        entity.setEmailAddress("a");
        entity.setName("name");
        entity.setPassword("qqq");
        entity.setPublicName("p");
        UserProfileInformation p = new UserProfileInformation(entity);
        entity.setUserProfileInformation(p);
        userDao.addUser(entity);
        return "login";
    }
}
  • 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-11T03:17:48+00:00Added an answer on June 11, 2026 at 3:17 am

    I think the problem is with the id generation strategy. For hibernate @GeneratedValue(strategy = GenerationType.AUTO) translates into a native identifier generation. This means that hibernate expects an identity id field for the UserTable.

    I don’t know exactly how SQLite works in terms of identity columns, but it seems from this SO question is a little different (see the second answer).

    Anyway if you plan to run your application on multiple databases is better for portability to change the id generation strategy from GenerationType.AUTO and use hibernate enhanced generators: SequenceStyleGenerator or TableGenerator. See this link in the hibernate documentation.

    EDIT:

    I tried to reproduce your problem, and it seems that SQLite dialect is not among the officially supported hibernate dialects. Meanwhile I tested your case with the H2 embeded database and it works as expected: your mappings are correct.

    If you are using an unofficial SQLite dialect it might be a bug with this dialect.

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

Sidebar

Related Questions

i wanted to create a topic model. this model would have a foreign key,
I wanted to create smth similar to this one Kansas county map where user
I wanted to create one js file which includes every js files to attach
I wanted to create a function of a certain type. I've found one way
I wanted to create an IDN-aware formencode validator to use in one of my
Wanted to create a fun app with photo. This is the scenario: I have
I wanted to create a tag like: #{some_tag entity:user, field:'name'} and expect it to
I wanted to create an HTML page which would have a set search criterias.
I wanted to create a counter that updates by one, every time it satisfied
I wanted to create a new property on a table in my model.. Basically

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.