使用CGLIB设置属性值的异常

use*_*343 4 java hibernate cglib

附加新备份的数据库后,我得到一个例外:

Caused by: org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.mytest.User.setPrimaryAccount
Run Code Online (Sandbox Code Playgroud)

在我的User类中,我有以下字段:

...

    private boolean isPrimaryAccount;

    public boolean getPrimaryAccount() {
        return isPrimaryAccount;
    }

    public void setPrimaryAccount(boolean primaryAccount) {
        isPrimaryAccount = primaryAccount;
    }

...
Run Code Online (Sandbox Code Playgroud)

从这里开始给出异常的引用异常?

Õzb*_*bek 8

附加新备份数据库后

我认为,您的数据库表中有可为空的列,并且您在持久化类中使用了primitve类型的boolean(不能设置为null).我认为这就是你得到这个例外的原因.

Hibernate建议你:

我们建议您在持久化类上声明一致命名的标识符属性,并使用可空(即非原始)类型.

将布尔值更改为布尔值,这可能会有所帮助......