Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Bidirectional mapping is giving recusrsion on owning side repository save

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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: 21266
138
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • 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: 4
  • Mark post as helpful
  • send pies
  • 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: 4
  • Mark post as helpful
  • send pies
  • 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: 4
  • Mark post as helpful
  • send pies
  • 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: 21266
138
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • 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.
 
Are we home yet? Wait, did we forget the tiny ad?
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!