'Spring JPA entity findBy<Parameter> method giving values in 1st attempt and null in 2nd call?
I have a Spring JPA method to get entity -> findBy<SomeCode>(). The spring boot application comes up and on making a 1st rest call the entity comes up with all values filled. When tried with 2nd attempt the two entity members coming 'null' which should not be - as other values are there. And there is data in db.
This goes on alternate basis i.e. if I run again 3rd it comes up filled up while on 4th attempt two entity members again come null.
The code log line is as below -
Site site = siteRepo.findByCode(inputSiteCode);
if (site != null) {
log.info("UPDATION CASE");
log.info("site code -> "+ site.getCode()+" lat -> "+ site.getLat() +" lng -> "+ site.getLng() );
My entity piece which is coming null on alternate runs
@Column(precision = 9, scale = 6)
private BigDecimal lat;
@Column(precision = 9, scale = 6)
private BigDecimal lng;
Repository:
@Repository
public interface SiteRepository extends JpaRepository<Site, Integer> {
public List<Site> findAll();
public Site findAllById(int id);
public Site findByCode(Integer code);
}
The two logs in 2 calls are as follows:
- Success case logs
Hibernate: select site0_.id as id1_6_, site0_.address as address2_6_, site0_.city as city3_6_, site0_.code as code4_6_, site0_.details as details5_6_, site0_.lat as lat6_6_, site0_.lng as lng7_6_, site0_.name as name8_6_, site0_.scheduler_id as schedule9_6_, site0_.state as state10_6_, site0_.zip as zip11_6_ from mow_site site0_ where site0_.code=?
2022-05-22 21:55:27.931 INFO 44064 --- [cTaskExecutor-5] c.m.d.b.SiteDataProcessor : UPDATION CASE
2022-05-22 21:55:27.931 INFO 44064 --- [cTaskExecutor-5] c.m.d.b.SiteDataProcessor : site code -> 83 lat -> 32.638450 lng -> -97.347690
address -> 7501 JBrown Rd
- Failure (Empty lat/lng) Case
Hibernate: select site0_.id as id1_6_, site0_.address as address2_6_, site0_.city as city3_6_, site0_.code as code4_6_, site0_.details as details5_6_, site0_.lat as lat6_6_, site0_.lng as lng7_6_, site0_.name as name8_6_, site0_.scheduler_id as schedule9_6_, site0_.state as state10_6_, site0_.zip as zip11_6_ from mow_site site0_ where site0_.code=?
2022-05-22 21:56:57.356 INFO 44064 --- [cTaskExecutor-6] c.m.d.b.SiteDataProcessor : UPDATION CASE
2022-05-22 21:56:57.364 INFO 44064 --- [cTaskExecutor-6] c.m.d.b.SiteDataProcessor : site code -> 83 lat -> null lng -> null
address -> 7501 JBrown Rd
I would appreciate the help. Thanks
Solution 1:[1]
There is no issue in spring jpa find method what I just found out.
It was something written after each successful call which is making the columns null and then when I was trying they came null and refilled again.
I apologise for wasting your time. I will be deleting the post after sometime as this is not at all the issue.
Thanks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Bhaskar |
