NutzCN Logo
问答 复合主键生创建sql问题
发布于 3124天前 作者 Rekoe 2666 次浏览 复制 上一个帖子 下一个帖子
标签:

code

import java.io.Serializable;

import org.nutz.dao.entity.annotation.Column;
import org.nutz.dao.entity.annotation.Index;
import org.nutz.dao.entity.annotation.Name;
import org.nutz.dao.entity.annotation.PK;
import org.nutz.dao.entity.annotation.Readonly;
import org.nutz.dao.entity.annotation.Table;
import org.nutz.dao.entity.annotation.TableIndexes;

/**
 * 项目组用户
 */
@Table("pj_gr_usr")
@PK({ "pj", "usr", "gr" })
@TableIndexes({ @Index(name = "FK_Reference_10", fields = { "pj", "gr" }, unique = false), @Index(name = "FK_Reference_9", fields = { "usr" }, unique = false) })
public class PjGrUsr implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -2031955995574649327L;
	/**
	 * 项目
	 */
	@Name
	private String pj;
	/**
	 * 用户
	 */
	@Column
	private String usr;
	/**
	 * 用户姓名
	 */
	@Readonly
	private String usrName;
	/**
	 * 组
	 */
	@Column
	private String gr;

	/**
	 * @return 项目
	 */
	public String getPj() {
		return pj;
	}

	/**
	 * @param pj
	 *            项目
	 */
	public void setPj(String pj) {
		this.pj = pj;
	}

	/**
	 * @return 用户
	 */
	public String getUsr() {
		return usr;
	}

	/**
	 * @return 用户姓名
	 */
	public String getUsrName() {
		return usrName;
	}

	/**
	 * @param usrName
	 *            用户姓名
	 */
	public void setUsrName(String usrName) {
		this.usrName = usrName;
	}

	/**
	 * @param usr
	 *            用户
	 */
	public void setUsr(String usr) {
		this.usr = usr;
	}

	/**
	 * @return 组
	 */
	public String getGr() {
		return gr;
	}

	/**
	 * @param gr
	 *            组
	 */
	public void setGr(String gr) {
		this.gr = gr;
	}

}

生成的sql

CREATE TABLE `pj_gr_usr` (
  `pj` varchar(50) NOT NULL,
  `usr` varchar(50) DEFAULT NULL,
  `gr` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`pj`),
  UNIQUE KEY `pj` (`pj`),
  KEY `FK_Reference_10` (`pj`,`gr`),
  KEY `FK_Reference_9` (`usr`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
3 回复

... 联合主键@Pk与字符主键@Name混搭啊。。。

然而并没有啊.....

@Table("YDM_ASSETS_INFO")
@PK({"type","no"})
public class AssetsInfoEntity {
	
	@Column("No")
	@Comment("资产编号")
	@Prev({
		@SQL( db = DB.ORACLE, value = "select @state || decode(max(no)," + 
				"null," + 
				"'000001'," + 
				"lpad(" + 
				"substr(max(no), instr(translate(max(no), '0123456789', '0000000000'),'0')) + 1, " + 
				"length(max(no)) - length(@state), " + 
				"'0'" + 
				")" + 
				")" + 
				"from ydm_assets_info " + 
				"where type = @type" + 
				"and name = @name")
	})
	public String no;

	@Column("type")
	@Comment("类型")
	public String type;
	
	@Column("NAME")
	@Comment("名称")
	public String name;
	
	@Column("BATCH_ID")
	@Comment("归属申请批次号,对应apply_info表中的ID")
	public String batchId;
	
	@Column("state")
	@Comment("资产状态:正常/销毁")
	public String state;
	
	@Column("prefix")
	@Comment("编号前缀/简称")
	public String prefix;


}

@PK有name属性

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