Home > front end >  does JPQL not have an * symbol?
does JPQL not have an * symbol?

Time:12-31

@Repository
public interface ParticipantRepository extends CrudRepository<Participant,Integer> {

    @Query("select e from Participant e WHERE e.event.venue =:venue")
    List<Participant> getParticipantsByEventVenue(String venue);
}

As you can see here ^ I have to use e to represent the * symbol. Is that just how JPQL works?

is there an * symbol in JPQL?

CodePudding user response:

Yes, it is particular syntax for JPQL. But if you like to use native SQL query, it is also possible as follows:

@Repository
 public interface ParticipantRepository extends
 JpaRepository<Participant,Integer> {
 @Query("select * from Participant e WHERE
 e.event.venue =:venue",nativeQuery = true)
 List<Participant> getParticipantsByEventVenue(String venue);}

also it is recommender to use JpaRepository instead of crudRepository.

CodePudding user response:

Yes, JPQL does not have an * symbol. Instead, you can use e to represent the entity in the FROM clause. For example, if you have a Participant entity, you can use e to represent all the columns of the Participant table in the SELECT clause, like this:

SELECT e FROM Participant e

This will select all the columns of the Participant table. If you want to select specific columns, you can list them after the SELECT clause, separated by commas. For example:

SELECT e.id, e.name FROM Participant e

This will select only the id and name columns of the Participant table.

  • Related