NutzCN Logo
问答 PoJo类映射建表失败
发布于 2532天前 作者 Reone 1514 次浏览 复制 上一个帖子 下一个帖子
标签:

MainSetup 中自动建表

val dao = nc.ioc.get(Dao::class.java)
        Daos.createTablesInPackage(dao, "com.reone.onepass.model", false)

UserAuth类中,表名t_user_auth

@Name
    @ColDefine(type = ColType.VARCHAR , width = 32)
    @Prev(els = {@EL("uuid()")})
    private String id;
    /**
     * 用户Id
     */
    @Column
    private int userId;

    @One(field = "userId")
    private User user;

User类中,表名t_user

    @Id
    private int id;
    /**
     * 用户账户信息Id
     */
    private String authId;

    /**
     * 用户账户信息
     */
    @One(field = "authId")
    private UserAuth auth;

运行报错

Table 't_user_auth' doesn't exist!
org.nutz.dao.DaoException: Invalid @One(field=authId) 'auth' : class com.reone.onepass.model.User<=>class com.reone.onepass.model.UserAuth

是我写的有什么问题么

5 回复

把两个类都贴完整

package com.reone.onepass.model;

import org.nutz.dao.entity.annotation.*;

import java.io.Serializable;
import java.util.List;

/**
 * 用户
 */
@Table("t_user")
@Comment("用户信息")
public class User implements Serializable{

    private static final long serialVersionUID = -7584476123328037939L;

    @Id
    private int id;

    /**
     * 姓名
     */
    @Column
    @ColDefine(width = 20)
    private String name;

    /**
     * 昵称
     */
    @Column
    @ColDefine(width = 20)
    private String nickName;

    /**
     * 性别
     */
    @Column
    private short gender;

    /**
     * 年龄
     */
    @Column
    private int age;

    /**
     * 身高
     */
    @Column
    private int height;

    /**
     * 体重
     */
    @Column
    private int weight;

    /**
     * 头像
     */
    @Column
    private String headShot;

    /**
     * 签名
     */
    @Column
    private String signature;

    /**
     * 地址
     */
    @Column
    private String address;

    /**
     * 获赞数
     */
    @Column
    private int beLikedNum;

    /**
     * 粉丝
     */
    @Column
    private int fansNum;

    /**
     * 关注数
     */
    @Column
    private int followNum;

    /**
     * 创建用户的时间
     */
    @Column
    private long createdTime;

    /**
     * 活动时间
     */
    @Column
    private long modifiedTime;

    /**
     * 用户设置ID
     */
    @Column
    private String settingId;

    /**
     * 用户设置
     */
    @One(field = "settingId")
    private UserSetting setting;

    /**
     * 用户账户信息Id
     */
    private String authId;

    /**
     * 用户账户信息
     */
    @One(field = "authId")
    private UserAuth auth;

    /**
     * 代表作,视频
     */
    @Many(field = "id")
    private List<Work> works;

    /**
     * 代表作,剧本
     */
    @Many(field = "id")
    private List<Script> scripts;

    public String getSettingId() {
        return settingId;
    }

    public void setSettingId(String settingId) {
        this.settingId = settingId;
    }

    public String getAuthId() {
        return authId;
    }

    public void setAuthId(String authId) {
        this.authId = authId;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    public short getGender() {
        return gender;
    }

    public void setGender(short gender) {
        this.gender = gender;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public int getWeight() {
        return weight;
    }

    public void setWeight(int weight) {
        this.weight = weight;
    }

    public String getHeadShot() {
        return headShot;
    }

    public void setHeadShot(String headShot) {
        this.headShot = headShot;
    }

    public String getSignature() {
        return signature;
    }

    public void setSignature(String signature) {
        this.signature = signature;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public List<Work> getWorks() {
        return works;
    }

    public void setWorks(List<Work> works) {
        this.works = works;
    }

    public List<Script> getScripts() {
        return scripts;
    }

    public void setScripts(List<Script> scripts) {
        this.scripts = scripts;
    }

    public int getBeLikedNum() {
        return beLikedNum;
    }

    public void setBeLikedNum(int beLikedNum) {
        this.beLikedNum = beLikedNum;
    }

    public int getFansNum() {
        return fansNum;
    }

    public void setFansNum(int fansNum) {
        this.fansNum = fansNum;
    }

    public int getFollowNum() {
        return followNum;
    }

    public void setFollowNum(int followNum) {
        this.followNum = followNum;
    }

    public long getCreatedTime() {
        return createdTime;
    }

    public void setCreatedTime(long createdTime) {
        this.createdTime = createdTime;
    }

    public long getModifiedTime() {
        return modifiedTime;
    }

    public void setModifiedTime(long modifiedTime) {
        this.modifiedTime = modifiedTime;
    }

    public UserSetting getSetting() {
        return setting;
    }

    public void setSetting(UserSetting setting) {
        this.setting = setting;
    }

    public UserAuth getAuth() {
        return auth;
    }

    public void setAuth(UserAuth auth) {
        this.auth = auth;
    }
}

package com.reone.onepass.model;

import org.nutz.dao.entity.annotation.*;

import java.io.Serializable;

/**
 * 用户唯一标识
 */
@Table("t_user_auth")
@Comment("用户唯一标识")
public class UserAuth implements Serializable{

    private static final long serialVersionUID = 278945725695102837L;

    @Name
    @ColDefine(type = ColType.VARCHAR , width = 32)
    @Prev(els = {@EL("uuid()")})
    private String id;

    /**
     * 密码
     */
    @Column
    @ColDefine(notNull = true)
    private String password;

    /**
     * 手机号
     */
    @Column
    private String phone;

    /**
     * 邮箱
     */
    @Column
    private String email;

    /**
     * 微信
     */
    @Column
    private String wechatId;

    /**
     * QQ
     */
    @Column
    private String qqId;

    /**
     * 微博
     */
    @Column
    private String weiboId;

    /**
     * 用户Id
     */
    @Column
    private int userId;

    @One(field = "userId")
    private User user;

    public int getUserId() {
        return userId;
    }

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

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getWechatId() {
        return wechatId;
    }

    public void setWechatId(String wechatId) {
        this.wechatId = wechatId;
    }

    public String getQqId() {
        return qqId;
    }

    public void setQqId(String qqId) {
        this.qqId = qqId;
    }

    public String getWeiboId() {
        return weiboId;
    }

    public void setWeiboId(String weiboId) {
        this.weiboId = weiboId;
    }
}

authId少写了@Column

Column要么全写要么全部不写,看你的类,其实不需要写的

难了我好久,多谢!

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