• 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
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Spring Boot Hibernate/JPA one to one mapping

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am currently investigating shopizer open source (e-commerce) project -https://github.com/shopizer-ecommerce/shopizer . Looking to add additional functionality where user can send requests for own products.

As every request would be mapped to only one product I decided to use one to one relation. Here are models created:

CustomProduct.java:


Here is cutom image associated with it:




During repo create call I've been given following error:



I can see, that CUSTOM_PRODUCT_IMAGE_ID value is being set from the logs, however, for some reason JPA/Hibernate thinks it is null. I can't understand why, I've played various scenarios but seems like every of them fails similar way.

Maybe, there is need to update bean of repository implementation to accept this nested one to one scenario?

Sorry, if there are some fundamental errors in above code, I've just started to play around with Spring and might be missing something very basic. Please let me know, if that's a case.

Just for reference of bean being created for custom repository:



P.S. sorry, had to shorten text, as by javaranch rules
 
Germans Zaharovs
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Never mind, I have checked database, it clearly referred to column, which I wouldn't expect:



Probably it has been created during various tests I've made before.

Regardless, once I've re-created database tables with only columns as per entities -> everything seems to work perfectly!
 
Ranch Hand
Posts: 128
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you have the tests that affect the structure of the database. You must always roll back after executing the test. As a rule of thumb, your test must test the existing structure, not alter it.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic