如果一张表内既有主键@Name由于唯一性索引,那么用fetch进行查找的时候,是查@name还是唯一性索引?
比如我的产品库存表中,既有自身的uuid,也有唯一unique外键product_id,那么用fetch优先查谁?
参考文档:
取得 Fetch
根据名称获取 (如果你的实体声明了 @Name 字段, 字符型主键,或者带唯一性索引的字段)
Person p = dao.fetch(Person.class,"Peter");
System.out.println(p.getId());
我的代码:
@Table("product_inventory")
@TableIndexes({@Index(name="idx_product_inventory_product_id",fields={"productId"},unique=true)})
public class ProductInventory extends BaseModel implements Serializable {
private static final long serialVersionUID = 1L;
@Column
@Name
@Comment("ID")
@ColDefine(type = ColType.VARCHAR, width = 32)
@Prev(els = {@EL("uuid()")})
private String id;
@Column("product_id")
@Comment("产品ID")
@ColDefine(type = ColType.VARCHAR, width = 32)
private String productId;