1

I am querying the DB to get the result but I get blank array

The repository class

@Repository public interface AppConfigRepository extends CrudRepository<AppConfig, Long> { @Query("SELECT n FROM AppConfig n WHERE n.appCode = ?1 and n.appVersion = ?2") List<AppConfig> findByCodeAndVersion(String appCode, String appVersion); } 

The table class

@Entity @Table(name = "app_config") @EntityListeners(AuditingEntityListener.class) public class AppConfig { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(columnDefinition = "serial") private long id; @Column(name = "app_code", nullable = false) private String appCode; @Column(name = "app_name", nullable = false) private String appName; @Column(name = "api_url", nullable = true) private String apiUrl; @Column(name = "db_name", nullable = true) private String dbName; @Column(name = "app_version", nullable = false) private String appVersion; 

The mapping function

@RequestMapping(value = "/config", params = { "appCode", "appVersion" }, method = RequestMethod.GET) public List<AppConfig> getConfig(@RequestParam(value = "appCode", required = true) String appCode, @RequestParam(value = "appVersion", required = true) String appVersion) { System.out.println(appCode); System.out.println(appVersion); return configRepository.findByCodeAndVersion(appCode, appCode); } 

This is how I am making the URL

http://localhost:9090/api/v1/config?appCode=MANDL_LIVE&appVersion=12.0 

In the logs I see

select appconfig0_.id as id1_0_, appconfig0_.api_url as api_url2_0_, appconfig0_.app_code as app_code3_0_, appconfig0_.app_name as app_name4_0_, appconfig0_.app_version as app_vers5_0_, appconfig0_.db_name as db_name6_0_ from app_config appconfig0_ where appconfig0_.app_code=? and appconfig0_.app_version=? 

1 Answer 1

2

You are calling:

return configRepository.findByCodeAndVersion(appCode, appCode); 

Shouldn't it be:

return configRepository.findByCodeAndVersion(appCode, appVersion); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.