NutzCN Logo
精华 通过项目启动建表正常 但是先建表再启动项目初始化就报错 这个怎么解决 user_id这个主键总是空
发布于 3215天前 作者 leecardo 2457 次浏览 复制 上一个帖子 下一个帖子
标签:
For example:> "INSERT INTO wx_sysuser(account,actpswd,nickname,login_cnt,last_login_time,lock_status) VALUES('admin','19485e369c691fa8ece1fabc8a6ceabfb5666b79','admin',0,NULL,'1') "
2016-01-27 17:43:19,189 org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:90) DEBUG - SQLException
java.sql.SQLIntegrityConstraintViolationException: ORA-01400: cannot insert NULL into ("POSP_CUSTOMER"."WX_SYSUSER"."USER_ID")

	at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:447)
	at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
	at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:951)
	at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:513)
	at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:227)
	at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531)
	at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:208)
	at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:1046)
	at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1336)
	at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3613)
	at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3714)
	at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:1378)
	at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:2931)
	at com.alibaba.druid.filter.FilterEventAdapter.preparedStatement_execute(FilterEventAdapter.java:440)
	at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:2929)
	at com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl.execute(PreparedStatementProxyImpl.java:131)
	at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:493)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor._runPreparedStatement(NutDaoExecutor.java:266)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:81)
	at org.nutz.dao.impl.DaoSupport$DaoExec.invoke(DaoSupport.java:264)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:64)
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:219)
	at org.nutz.dao.impl.EntityOperator.exec(EntityOperator.java:50)
	at org.nutz.dao.impl.NutDao.insert(NutDao.java:144)
	at org.jiujiu.init.InitDB.createDB(InitDB.java:47)
	at org.jiujiu.init.SetupMethod.init(SetupMethod.java:32)
	at org.nutz.mvc.impl.NutLoading.evalSetup(NutLoading.java:270)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:119)
	at org.nutz.mvc.ActionHandler.<init>(ActionHandler.java:19)
	at org.nutz.mvc.NutFilter.init(NutFilter.java:77)
	at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)
	at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
	at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)
	at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4855)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5549)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
	at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1095)
	at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1930)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)

---------------初始化的代码是这样的

 public static void createDB(NutDao dao) {
        for (Class<?> table : tables) {
            if (!dao.exists(table)) {
                dao.create(table, false);
            }
        }
        // add sys user
        if(dao.count(Sysuser.class)==0){
        	Sysuser user = new Sysuser();
        	user.setUserId(1);
        	user.setNickname("admin");
        	user.setAccount("admin");
        	user.setLockStatus("1");
        	user.setLoginCnt(0);
        	user.setActpswd(Lang.sha1("1234qwer"));
        	dao.insert(user);
        }
		}

-------实体

/**
* 系统用户
*/
@Table("wx_sysuser")
public class Sysuser {

	/**
	 * 管理员唯一标识
	 */
	@Id
	@Column("user_id")
	private Integer userId;
	/**
	 * 用户名
	 */
	@Column("account")
	private String account;
	/**
	 * 密码
	 */
	@Column("actpswd")
	private String actpswd;
	/**
	 * 用户昵称
	 */
	@Column("nickname")
	private String nickname;
	/**
	 * 登录次数
	 */
	@Column("login_cnt")
	private Integer loginCnt;
	/**
	 * 最后登录时间
	 */
	@Column("last_login_time")
	private Date lastLoginTime;
	/**
	 * 1 表示正常,0 表示锁定
	 */
	@Column("lock_status")
	private String lockStatus;

	public Sysuser() {
	}

	public Sysuser(Integer userId) {
		this.userId = userId;
	}

	public Integer getUserId() {
		return userId;
	}

	public void setUserId(Integer userId) {
		this.userId = userId;
	}

	public String getAccount() {
		return account;
	}

	public void setAccount(String account) {
		this.account = account;
	}

	public String getActpswd() {
		return actpswd;
	}

	public void setActpswd(String actpswd) {
		this.actpswd = actpswd;
	}

	public String getNickname() {
		return nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	public Integer getLoginCnt() {
		return loginCnt;
	}

	public void setLoginCnt(Integer loginCnt) {
		this.loginCnt = loginCnt;
	}

	public Date getLastLoginTime() {
		return lastLoginTime;
	}

	public void setLastLoginTime(Date lastLoginTime) {
		this.lastLoginTime = lastLoginTime;
	}

	public String getLockStatus() {
		return lockStatus;
	}

	public void setLockStatus(String lockStatus) {
		this.lockStatus = lockStatus;
	}
	}
3 回复

是初始化 user.setUserId(1); 这个地方有问题吗?

还是我自己建的sequence他查找不到??

自己建seq的话加@Prev

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