1. From what I can see, in your repository your method name is defined as 'getproductName', but in your entity class, you are using 'getProductName', the naming must be identical, update your repository method to -
String getProductName(@Param("productId") String productId);
2. In your entity class, you are injecting the 'ProductTypeRepository' trying to call the 'getproductName' method. This is not the correct way to use a repository in a service or entity class. Repositories should be used in service classes or controllers. You can creat a service class 'ProductService' that uses the 'ProductTypeRepository' to retrieve the product name. You can then inject the 'ProductServic'e into your transaction controller and call the 'getProductName' method to include the product name -
@Service
public class ProductService {
private final ProductTypeRepository productRepository;
public ProductService(ProductTypeRepository productRepository) {
this.productRepository = productRepository;
}
public String getProductName(String productId) {
if (productId != null) {
return productRepository.getProductName(productId);
}
return null;
}
}
3. Update your transaction controller to include the 'ProductService' -
@RestController
@RequestMapping("/transactions")
public class TransactionController {
private final ProductService productService;
public TransactionController(ProductService productService) {
this.productService = productService;
}
@GetMapping("/{transactionId}")
public ResponseEntity<Transaction> getTransaction(@PathVariable("transactionId") String transactionId) {
Transaction transaction = ...;
String productName = productService.getProductName(transaction.getProductId());
transaction.setProductName(productName);
return ResponseEntity.ok(transaction);
}
}
The above code is based on what you gave in your code, you need to adjsut it to run error free depending on the rest of your code.