更新
我从MySQL中删除了视图并修改了实体的注释(我也修改了类名)。这现在有效,但我仍然不明白为什么我无法将hibernate映射到视图。
@Entity
@SqlResultSetMapping(name = "implicit", entities = @EntityResult(entityClass = vsg.ecotrak.admin.view.domain.CustomerProgramQtyInquiry.class))
@NamedNativeQuery(name = "VCPQuantity.findByCustomerProgram",
query = "select (cust.id * 1000000000) + (s.id * 1000000) + (p.id * 1000) as id, "
+ " cust.client as customer, "
+ " cust.id as customer_id, "
+ " cust.status as customer_status, "
+ " p.name as program_name, "
+ " p.id as program_id, "
+ " p.program_type, "
+ " p.refill_type, "
+ " p.status as program_status, "
+ " s.store_name, "
+ " s.store_number, "
+ " s.status as store_status, "
+ " sic.qty_on_hand, "
+ " ps.re_order_qty, "
+ " ps.trigger_qty, "
+ " ps.initial_order_qty, "
+ " ps.is_overridden "
+ " from program as p "
+ " join program_store as ps on ps.program_id = p.id "
+ " join customer as cust on cust.id = ps.customer_id "
+ " join store as s on s.id = ps.store_id "
+ " join store_inv_cnt as sic on sic.store_id = ps.store_id and sic.customer_id = ps.customer_id and sic.program_id = ps.program_id "
+ " where cust.id = :customerId and p.id = :programId "
+ " order by cust.client, s.store_name, s.store_number",
resultSetMapping = "implicit")
使用Spring 2.5.6 Hibernate(JBoss 5.1附带的那个)
MySQL 5.1
当我查看日志文件时,我注意到我没有看到以下内容:来自带注释的类的绑定实体:相关实体的条目。
当我运用代码时,我收到以下异常:org.hibernate.MappingException:未知的命名查询:VCPQuantity.findByCustomerProgram
我真的没看到实施有什么问题。寻找一些方向。
这就是我所拥有的:
数据库视图:
CREATE OR REPLACE VIEW VCPQUANTITY AS
select (cust.id * 1000000000) + (s.id * 1000000) + (p.id * 1000) as id,
cust.client as customer,
cust.id as customer_id,
cust.status as customer_status,
p.name as program_name,
p.id as program_id,
p.program_type,
p.refill_type,
p.status as program_status,
s.store_name,
s.store_number,
s.status as store_status,
sic.qty_on_hand,
ps.re_order_qty,
ps.trigger_qty,
ps.initial_order_qty,
ps.is_overridden
from program as p
join program_store as ps on ps.program_id = p.id
join customer as cust on cust.id = ps.customer_id
join store as s on s.id = ps.store_id
join store_inv_cnt as sic on sic.store_id = ps.store_id and sic.customer_id = ps.customer_id and sic.program_id = ps.program_id
order by cust.client, s.store_name, s.store_number;
实体:
@Entity
@Table(name="vcpquantity")
@SqlResultSetMapping(name = "implicit", entities = @EntityResult(entityClass = vsg.ecotrak.admin.view.domain.VCPQuantity.class))
@NamedNativeQuery(name = "VCPQuantity.findByCustomerProgram", query = "select * from vcpquantity where customerId = :customerId and programId = :programId", resultSetMapping = "implicit")
public class VCPQuantity implements java.io.Serializable
{
private static final long serialVersionUID = 7676279337195536457L;
@Id
@Column(name = "ID", nullable = false)
private Long id;
@Column(name = "customer_id")
private Long customerId;
@Column(name = "customer")
private String customer;
@Column(name = "customer_status")
private String customerStatus;
@Column(name = "program_id")
private Long programId;
@Column(name = "program_name")
private String programName;
@Column(name = "program_type")
private String programType;
@Column(name = "refill_type")
private String refillType;
@Column(name = "program_status")
private String programStatus;
@Column(name = "store_name")
private String storeName;
@Column(name = "store_number")
private String storeNumber;
@Column(name = "store_status")
private String storeStatus;
@Column(name = "qty_on_hand")
private Long qtyOnHand;
@Column(name = "re_order_qty")
private Long reOrderQty;
@Column(name = "trigger_qty")
private Long triggerQty;
@Column(name = "initial_order_qty")
private Long initialOrderQty;
@Column(name = "is_overridden")
private boolean overridden;