【发布时间】:2016-12-29 07:18:33
【问题描述】:
我在 spring 中使用 JPA 查询,我的子类扩展了 Baseclass,其中仅包含一个 Id 并且我的子类具有下面给出的 JPA 查询使用的所有变量:
基类:
@MappedSuperclass
@Table(name = "partcost")
@NoArgsConstructor
@AllArgsConstructor
@Data
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class Pg6p0012_01PartCostBaseQueryModel implements Serializable {
private static final long serialVersionUID = 1L;
@Id
String part_no;
}
子类:
@Entity
@Table(name = "partcost")
@NoArgsConstructor
@AllArgsConstructor
@Data
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class Pg6p0012_01PartCost1QueryModel extends Pg6p0012_01PartCostBaseQueryModel implements Serializable {
private static final long serialVersionUID = 1L;
private String stock_take_cost ;
private String cost_type ;
}
当我在 JPA Query 下方点击时:
@Repository
@Transactional
public interface Pg6p0012_01PartcostRepository extends JpaRepository<Pg6p0012_01PartCostBaseQueryModel, String> {
@Query(value = "SELECT stock_take_cost,cost_type FROM partcost where part_no = :p_part_no", nativeQuery = true)
public List<Pg6p0012_01PartCost1QueryModel>getPartcost1Result(@Param("p_part_no") String p_part_no);
}
它的抛出错误:没有这样的列名 这很清楚,因为查询只返回一列,但模型有两列。
如何解决这个问题?请提出建议。
【问题讨论】:
-
当 JPQL 非常适合这种情况时,用户会使用“本机查询”(SQL)。
-
@Neil Stockton:这是一个老项目,我不应该改变结构
-
尝试用
?1替换您的:p_part_no并删除@Param注释?
标签: java sql spring spring-data spring-data-jpa