PSQLException: The column name clazz_ was not foun

2019-03-04 08:21发布

I am trying to fetch a PlaceEntity. I've previously stored a bunch of GooglePlaceEntity objects where

@Entity
@Table(name = "place")
@Inheritance(
        strategy = InheritanceType.JOINED
)
public class PlaceEntity extends AbstractTimestampEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
}

and

@Entity
@Table(name = "google_place")
public class GooglePlaceEntity extends PlaceEntity {
    // Additional fields ..
}

However, neither do I want to send information stored in google_place nor do I want to load it unnecessarily. For this reason I am only fetching

public interface PlaceRepository extends JpaRepository<PlaceEntity, Long> {

    @Query(value = "" +
            "SELECT * " +
            "FROM place " +
            "WHERE earth_distance( " +
            "   ll_to_earth(place.latitude, place.longitude), " +
            "   ll_to_earth(:latitude, :longitude) " + 
            ") < :radius",
            nativeQuery = true)
    List<PlaceEntity> findNearby(@Param("latitude") Float latitude,
                                 @Param("longitude") Float longitude,
                                 @Param("radius") Integer radius);

}

and what I get is this:

org.postgresql.util.PSQLException: The column name clazz_ was not found in this ResultSet.
    at org.postgresql.jdbc.PgResultSet.findColumn(PgResultSet.java:2588) ~[postgresql-9.4.1208-jdbc42-atlassian-hosted.jar:9.4.1208]
    at org.postgresql.jdbc.PgResultSet.getInt(PgResultSet.java:2481) ~[postgresql-9.4.1208-jdbc42-atlassian-hosted.jar:9.4.1208]
    at com.zaxxer.hikari.pool.HikariProxyResultSet.getInt(HikariProxyResultSet.java) ~[HikariCP-2.7.8.jar:na]
    at org.hibernate.type.descriptor.sql.IntegerTypeDescriptor$2.doExtract(IntegerTypeDescriptor.java:62) ~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:47) ~[hibernate-core-5.2.14.Final.jar:5.2.14.Final]
    ...

I am able to run this statement in pure PostgreSQL:

SELECT * FROM place WHERE 
earth_distance( 
  ll_to_earth(place.latitude, place.longitude), 
  ll_to_earth(17.2592522, 25.0632745)
) < 1500;

but not using the JpaRepository.

And by the way, fetching a GooglePlaceEntity is working however:

@Query(value = "" +
        "SELECT * " +
        "FROM place JOIN google_place ON google_place.id = place.id " +
        "WHERE earth_distance( " +
        "   ll_to_earth(place.latitude, place.longitude), " +
        "   ll_to_earth(:latitude, :longitude) " + 
        ") < :radius",
        nativeQuery = true)
List<GooglePlaceEntity> findNearby(@Param("latitude") Float latitude,
                                   @Param("longitude") Float longitude,
                                   @Param("radius") Integer radius);

0条回答
登录 后发表回答