如何解决在使用面对错误的postgresql排除主键之后执行NamedNativeQuery Join查询时,
我在结果输出中不需要ID(主键),但在排除查询和结果集中的ID后得到error.org.postgresql.util.PSQLException:在此ResultSet中找不到列名ID。 pa 因此,在格式化该实体类时需要帮助。
注意:的假定方式应类似于以下方法调用的entityManager.createNamedQuery(“ getPublisherInfoList”,PublisherInfoResponseEntity.class).getResultList();
@NamedNativeQueries(value = {
@NamedNativeQuery(
name = "getPublisherInfoList",query = "SELECT publisher.publisher_name,publisher.contact_name,publisher.contact_email,publisher.contact_phone,publisher.managed_services,\n" +
"annual.customers,annual.employees,annual.revenue,"
"FROM publisher_portal.publisher_informations publisher JOIN publisher_portal.publisher_annual annual\n" +
"ON publisher.publisher_name=annual.publisher_name",resultSetMapping = "PublisherInfoResponseMappings"
),@NamedNativeQuery(
name = "getPublisherByName",\n" +
"publisher.managed_services,annual.customers,\n" +
"FROM publisher_portal.publisher_informations publisher JOIN publisher_portal.publisher_annual annual\n" +
"ON publisher.publisher_name=annual.publisher_name where publisher.publisher_name= :publisherName",resultSetMapping = "PublisherInfoResponseMappings"
)
})
@SqlResultSetMapping(name = "PublisherInfoResponseMappings",entities = {
@EntityResult(entityClass = PublisherInfoResponseEntity.class,fields = {
@FieldResult(name = "publisher_name",column = "publisher_name"),@FieldResult(name = "contact_name",column = "contact_name"),@FieldResult(name = "contact_phone",column = "contact_phone"),@FieldResult(name = "contact_email",column = "contact_email"),@FieldResult(name = "managed_services",column = "managed_services"),})
})
@Entity
@Table(name="publisher_informations",schema="publisher_portal")
public class PublisherInfoResponseEntity {
@Id
private Long id;
private String publisher_name;
private String contact_name;
private String contact_phone;
private String contact_email;
private String managed_services;
//setters and getters
}
解决方法
看看您是否要在重新分配中排除某些列,只需对该特定名称使用 @Jsongnore 实体类中的列/字段。
因此解决方案将
在查询和结果集中包含主键,然后在主键上使用@Jsongnore,以使准备的结果集不具有字段ID。
注意,您可以在字段或getter方法中应用@Jsongnore
例如
@NamedNativeQueries(value = {
@NamedNativeQuery(
name = "getPublisherInfoList",query = "SELECT publisher.id,publisher.publisher_name,publisher.contact_name,publisher.contact_email,publisher.contact_phone,publisher.managed_services,\n" +
"annual.customers,annual.employees,annual.revenue,"
"FROM publisher_portal.publisher_informations publisher JOIN publisher_portal.publisher_annual annual\n" +
"ON publisher.publisher_name=annual.publisher_name",resultSetMapping = "PublisherInfoResponseMappings"
),@NamedNativeQuery(
name = "getPublisherByName",\n" +
"publisher.managed_services,annual.customers,\n" +
"FROM publisher_portal.publisher_informations publisher JOIN publisher_portal.publisher_annual annual\n" +
"ON publisher.publisher_name=annual.publisher_name where publisher.publisher_name= :publisherName",resultSetMapping = "PublisherInfoResponseMappings"
)
})
@SqlResultSetMapping(name = "PublisherInfoResponseMappings",entities = {
@EntityResult(entityClass = PublisherInfoResponseEntity.class,fields = {
@FieldResult(name = "id",column = "id")
@FieldResult(name = "publisher_name",column = "publisher_name"),@FieldResult(name = "contact_name",column = "contact_name"),@FieldResult(name = "contact_phone",column = "contact_phone"),@FieldResult(name = "contact_email",column = "contact_email"),@FieldResult(name = "managed_services",column = "managed_services"),})
})
@Entity
@Table(name="publisher_informations",schema="publisher_portal")
public class PublisherInfoResponseEntity {
@Id
@Jsongnore
private Long id;
private String publisher_name;
private String contact_name;
private String contact_phone;
private String contact_email;
private String managed_services;
//setters and getters
}
注意:假设已创建了entityManager.createNamedQuery(..)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。