作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 spring 中使用 JPA 查询,我的子类扩展了仅包含 Id 的 Baseclass,并且我的子类具有下面给出的 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 查询时:
@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);
}
抛出错误:没有这样的列名称这很清楚,因为查询仅返回一列,但模型有两列。
如何解决这个问题?请提出建议。
最佳答案
您将part_no设置为transient。这意味着它没有保留在数据库中。因此您将收到 no such columns name 错误。从part_no上方的基类中删除@Transient。
并用
注释你的基类@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
Hibernate 支持三种基本的继承映射策略:
table per class hierarchy
table per subclass
table per concrete class
关于java - JPA 查询结果为 No Identifier,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41374924/
我是一名优秀的程序员,十分优秀!