У меня есть простая система (Controller, Service, Repository), но даже если данные присутствуют в базе данных, служба возвращает нулевое значение
Data
mysql> select * from customer;
+----+---------------+
| id | username |
+----+---------------+
| 4 | liparistudios |
+----+---------------+
Домен
@Data
@Entity
@Table(name = "customer")
public class Customer implements Serializable {
private static final long serialVersionUID = 201811031445L;
@Id
@GeneratedValue( strategy = GenerationType.SEQUENCE )
private Long id;
private String username;
Контроллер
Customer c = customerService.searchCustomerByUsername( usernameToFind );
Сервис
@Service
public class CustomerService {
@Autowired
private CustomerRepo repo;
public Customer searchCustomerByUsername( String username ) {
return repo.findAllByUsername( username );
}
Хранилище
@Repository
@Transactional
public interface CustomerRepo extends JpaRepository<Customer, Long> {
@Query(
value = "SELECT * FROM Customer c WHERE username = ':username' ORDER BY username ASC LIMIT 1",
nativeQuery = true
)
public Customer findAllByUsername(@Param("username") String username );