• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Bidirectional mapping is giving recusrsion on owning side repository save

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Employee (empCode, empAddress, email)

LoginUser (userName, isLocked, empCode(fk @oneToOne))
LoginUser table contains empCode as foreign key.


I tried without cascade on both side too, everything. But, it’s going into infinite loop to StackOverFlowError.

Same for save employee too


I am getting Error. This scenario where CascadeType.ALL is even there
Caused by: org.hibernate.AssertionFailure: non-transient entity has a null id: com.titan.poss.user.dao.UserLogin

And in hashcode I am excluding the other Object too
 
Saloon Keeper
Posts: 26020
186
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch, Satish!

Your example lacks something. Your exception says "UserLogin" is not set, but no such column exists in your example code, only LoginUser.

What the error actually means is that you're attempting to store a record without having first assigned it a unique primary key value.
 
Satish Patro
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for the incnovenience.
I renamed Entity name before posting.

It will be
Caused by: org.hibernate.AssertionFailure: non-transient entity has a null id: com.titan.poss.user.dao.LoginUser.

I will edit it in the question.


"What the error actually means is that you're attempting to store a record without having first assigned it a unique primary key value."

But, I am setting both table's primary key & doing cascade all. How does it not have primary key?
 
Satish Patro
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
one temporary solution.
I am saving both repo differently.

Means no use of bidirectional mapping while saving.'But, when I am trying to fetch
LoginUser from Employee like

emp.getLoginUser(),
In trace, it's showing it's fetching both table, then shows StackOverflow error, even If I provide fetchtype lazy
 
Satish Patro
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Temporary solution what I am doing now is, saving both object differently from Repo. Not saving from owned side.

Employee emp = new Employee();
emp.setEmpCode(“Zenitsu”);
emp.setEmpCode(“NY”);
Employee responseEmp  = empRepo.save(emp);

LoginUser loginUser = new LoginUser();
loginUser.setUserName(“Zenitsu12”);
loginUser.setIsLocked(false);
loginUser.setEmployee(responseEmp);
loginRepo.save(loginUser);

But, fot fetching it's stackoverflow error as I mentioned in my previous comment
 
Tim Holloway
Saloon Keeper
Posts: 26020
186
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If saving now works, I'd recommend checking the database to make sure it saved exactly what you expected.

To resolve the fetch problem, I'd need to see the failing code and the stack trace.

Also, I just realized you posted to the Java in General forum, but this is an ORM question, so I'm moving the topic to the forum where the ORM experts live.
 
It's a pleasure to see superheros taking such an interest in science. And this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic