NutzCN Logo
问答 @Name和于唯一性索引,用fetch优先查谁?
发布于 1072天前 作者 wx_7qr0j9qpmienlificb6v 864 次浏览 复制 上一个帖子 下一个帖子
标签:

如果一张表内既有主键@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;
1 回复

这东西一试便知

添加回复
请先登陆
回到顶部