1

I would like to make a list of all participants in my controller but using snake_case in JpaRepository is generating errors

Example:

in sql I would do:

select * from participants p where p.game_a = 1;

In repository I tried to do this:

@Repository
public interface ParticipantRepository extends JpaRepository<Participant, Long> {
    List<Participant> findParticipantByGame_a(Game game_a);
}

Is there a way to do such thing using snake case or should I rename all properties in model to camel case to avoid this?

Error:

Failed to create query for method public abstract java.... No property game found for type Participant! Did you mean 'gameA'?

Using findParticipantByGameA or findParticipantBygameA does not work either

  • Maybe you want check that: https://stackoverflow.com/questions/29983047/spring-data-jpa-repository-methods-dont-recognize-property-names-with-underscor – Nahuel Giani Dec 06 '21 at 19:14
  • Based on the SQL example, it looks like `findParticipantByGame_a(Game game_a)` should be something like `findParticipantByGame_a(long gameId)`. – Andrew S Dec 06 '21 at 19:14

1 Answers1

0

Underscore is a reserved character in spring data. Use Camelcase letters in entity fields (gameA) and then use @Column(name="game_a") to set the database column name, if you want to use Underscore in the database column name. but, to use this character in the entity field, you need to change JPA naming strategy in application.properties file. e.x. in hibernate:

spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.ImprovedNamingStrategy
N_R
  • 1