Akki
Akki

Reputation: 107

How to get column names of a table using spring data jpa

I am using spring boot, spring data JPA, I am searching for solution to get all column names of a given table. But could not found as per my requirements

Not want a solution with native query.Looking for general solution using spring data abstraction.

I am able to get the column names using normal java but i want to fetch them using spring data JPA.

Upvotes: 2

Views: 8147

Answers (1)

abhinavsinghvirsen
abhinavsinghvirsen

Reputation: 2054

they are several ways

public interface TableMetadataRepository extends JpaRepository<TableMetadata, TableMetadataKey>
{
  TableMetadata findByTableName(String tableName);
}

then you can go for

List<TableMetadata> metadata = tableMetadataRepository.findAll()
TableMetadata metadataofspecifictable = tableMetadataRepository.findByTableName("urtable");

Upvotes: 3

Related Questions