简体   繁体   English

Spring JPA 实体 findBy<Parameter> 在第一次尝试中给出值并在第二次调用中给出 null 的方法?

[英]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>().我有一个 Spring JPA 方法来获取实体 -> findBy<SomeCode>()。 The spring boot application comes up and on making a 1st rest call the entity comes up with all values filled. Spring Boot 应用程序启动并在进行第一次休息调用时,实体出现了所有填充的值。 When tried with 2nd attempt the two entity members coming 'null' which should not be - as other values are there.当尝试第二次尝试时,两个实体成员会出现“null”,这不应该是 - 因为存在其他值。 And there is data in db. db中有数据。

This goes on alternate basis ie if I run again 3rd it comes up filled up while on 4th attempt two entity members again come null.这是在交替的基础上进行的,即如果我再次运行第 3 次,它会被填满,而第 4 次尝试时,两个实体成员再次变为空。

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: 2次调用中的两次log如下:

  1. 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
  1. Failure (Empty lat/lng) Case失败(空 lat/lng)案例
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谢谢

There is no issue in spring jpa find method what I just found out.我刚刚发现的spring jpa find方法没有问题。

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谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 class 中将方法从第一种方法调用到第二种方法 - How to call method from 1st method to 2nd method in a class 如何通过从第1类调用第2类的方法来调用第3类的方法 - How to call a method of a 3rd class by calling the method of the 2nd class from the 1st class Java继承:第2个实例调用第1个实例方法 - Java Inheritance : 2nd instance calls 1st instance method 在更改第一微调器值时更改第二微调器值 - changing 2nd spinner values on changing 1st spinner value 尝试从第一类活动中调用方法,并在第二类活动中保留相同的参数(android studio) - Trying to call a method from 1st class activity and keep the same argument in a 2nd class activity (android studio) 关于第一个init()和第二个init() - regarding 1st init() and 2nd init() 检查第一个 if 条件,然后检查第二个 - Checking 1st if condition and then 2nd spring JPA的FindBy在传递空参数时使线程挂起 - FindBy of spring JPA makes the thread hang when passing a null parameter 如何用两个参数编写Mybatis XML Mapper(第一个是List <String> ,第二长)? - How to write Mybatis XML Mapper with two parameter (1st is List<String>, 2nd is Long)? 从第一个活动拨打电话后,第二个活动没有通话 - 2nd Activity doesn't call after calling from 1st Activity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM