@LazyToOne is deprecated, than what is the alternative to it ?
I had this code… but now it shows deprecated … what to do ?
@OneToOne(cascade = CascadeType.ALL, mappedBy = "animal", fetch = FetchType.LAZY)
@LazyToOne(value = LazyToOneOption.NO_PROXY)
@ToString.Exclude
@Valid
private Giraffe giraffe;
What do you want to express/achieve with this annotation? Chances are, you don’t need this anymore and you can simply remove the annotation.
Okay … When I simply remove this annotation … and retrieve an object of the class in which this girrafe onetoone relation was present (let’s say Main class) … this giraffe object was null in the retrieved entity i think.
Or may be it was loaded somehow but its child objects were null. or not loaded.
Example… I had this test… and It was failing on this line …
assertEquals(1, main.get().getMasterAnimal().getAdditionalInformation().size());
@Test
void mainCanBeFetchedByCrn() {
Main savedmain =
mainRepository.save(
mainRepositoryDataProvider.createValidmain());
entityManager.flush();
entityManager.clear();
List<Main> list =
mainRepository.findByReferenceNumberCrn(crn, mainStatus.DRAFT);
Optional<Main> main =
list.stream()
.filter(
x ->
x.getReferenceNumber() != null
&& x.getReferenceNumber()
.getCrn()
.getCrnNumber()
.equals(savedmain.getReferenceNumber().getCrn().getCrnNumber()))
.findAny();
assertTrue(main.isPresent());
log.info("fetching master Animal : ");
assertNotNull(main.get().getMasterAnimal());
log.info("fetching master Animals additional info : ");
**assertEquals(1, main.get().getMasterAnimal().getAdditionalInformation().size());**
}
If you think this is a bug, please create an issue in the issue tracker(https://hibernate.atlassian.net) with a test case(https://github.com/hibernate/hibernate-test-case-templates/blob/master/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java) that reproduces the issue.
Hello @beikov ,
Thank you for your response, I think the above issue might be related to this one.
https://hibernate.atlassian.net/browse/HHH-17258
Could you please suggest a workaround if the fix is not possible in near future.
Thanks.
As @mbladel answered on JIRA, this will be fixed with the next release, since it is a duplicate of [HHH-17228] - Hibernate JIRA