membersound
membersound

Reputation: 86747

Dynamic entity name in JpaRepository?

I'm using spring JpaRepository, and want to provide a generic interface with generic derived SQL queries as follows using el expressions:

public interface BaseRepo <B> extends CrudRepository<B, Long> {
    @Query("SELECT b FROM #{#entityName} b)
    List<B> findAllB();
}

@Entity
class Booking {} //results in "booking"

This works fine! But what if the desired entity contains an underscore? How could I define the strategy of how the el expressions translate the entity name?

@Entity
@Table(name = "booking_entity")
class BookingEntity {} //results in "bookingentity", missing underscore!

Upvotes: 0

Views: 3844

Answers (1)

Gregor Ra&#253;man
Gregor Ra&#253;man

Reputation: 3081

You could use the annotation @Entity(name="booking_entity").

Upvotes: 2

Related Questions