ORMLite:使用外键作为主键

时间:2018-08-16 18:46:34

标签: java foreign-keys ormlite

晚上好

使用下表中具有主键和外键的属性。

CREATE TABLE `user` (
`profile` INT(11) NOT NULL,
PRIMARY KEY (`profile`),
CONSTRAINT `user_ibfk_1` FOREIGN KEY (`profile`) REFERENCES `profile` 
COLLATE='utf8mb4_bin'
ENGINE=InnoDB;

我一直在尝试这样查询数据:

DaoManager.createDao(this.connectionSource, User.class).queryForEq("profile", number)

User.class:

@DatabaseTable(tableName = "User")
public class User implements Storeable {    

    @DatabaseField(id = true, foreign = true)
    private Profile profile;
}

但是无济于事

WARN graphql.execution.SimpleDataFetcherExceptionHandler - Exception while fetching data (/chat) : Id field profile cannot also be a foreign object
java.lang.IllegalArgumentException: Id field profile cannot also be a foreign object

(完整的堆栈跟踪:https://pastebin.com/JKHR3uay

那么避免这种改变数据库架构的唯一方法是吗?

0 个答案:

没有答案