Java 休眠调用错误的setter

Java 休眠调用错误的setter,java,hibernate,Java,Hibernate,我对hibernate从数据库加载一些bean的方式有一些问题 我们使用bean/beanHistoric结构来持久化对该bean所做的所有更改。当我们在一个bean实例中持久化一些更改时,我们使用相同的数据创建一个beanHistoric并保存它,这样做是为了使一些setter不完全是setter。 例如: @Entity public class beanHistoric { List<AnotherBeanHistoric> anotherBeanListH;

我对hibernate从数据库加载一些bean的方式有一些问题

我们使用bean/beanHistoric结构来持久化对该bean所做的所有更改。当我们在一个bean实例中持久化一些更改时,我们使用相同的数据创建一个beanHistoric并保存它,这样做是为了使一些setter不完全是setter。 例如:

@Entity
public class beanHistoric {
    List<AnotherBeanHistoric> anotherBeanListH;

    @OneToMany(mappedBy="beanHistoric", cascade=CascadeType.ALL, fetch=FetchType.EAGER)
    @Cascade({org.hibernate.annotations.CascadeType.ALL})
    public List<AnotherBeanHistoic> getAnotherBeanList(){
        return this.anotherBeanListH;
    }
    public void setAnotherBeanList(List<AnotherBean> anotherBeanList){
        for (AnotherBean anotherBean : anotherBeanList){
            anotherBeanListH.add(new AnotherBeanHistoric(anotherBean))
        }
    }

    private void setAnotherBeanListH(List<AnotherBeanHistoric> anotherBeanList){
        this.anotherBeanListH = anotherBeanList;
    }
}
@实体
公共级beanHistoric{
列出另一个列表;
@OneToMany(mappedBy=“beanHistoric”,cascade=CascadeType.ALL,fetch=FetchType.EAGER)
@级联({org.hibernate.annotations.CascadeType.ALL})
公共列表getAnotherBeanList(){
返回此。另一个beanlisth;
}
public void setAnotherBeanList(列出其他BeanList){
for(AnotherBean AnotherBean:AnotherBean列表){
添加(新的anotherBean历史(anotherBean))
}
}
私有void setAnotherBeanList(列出其他BeanList){
this.anotherBeanListH=另一个beanlist;
}
}
如您所见,该属性被写入另一个BeanList,但hibernate正在调用setAnotherBeanList,以便在从数据库加载对象后填充该对象,而不是setAnotherBeanList


知道为什么会发生这种情况吗?

好的,当我编辑问题并添加bean中使用的变量时,我意识到我的getter的名称是
getAnotherBeanList
,而不是
getAnotherBeanList

当我在getter中使用我的命名(我必须遵循的一些遗留样式)而不是属性本身时,hibernate似乎理解getter的名称就是属性的名称,因此要调用的setter是
getAnotherBeanList


在问这个问题之前应该仔细看一看,但我认为这是值得知道的。

您告诉Hibernate名为
anotherBeanList
的属性通过注释getter
getAnotherBeanList()
映射为OneToMany。因此,当从数据库读取实体时,它通过调用关联的setter来填充关联:
setAnotherBeanList()
。相反,这将是相当令人惊讶的。如果属性名为
foo
,为什么Hibernate会调用
setBar()

setAnotherBeanList
是私有的-尝试将其公开实体是如何映射的。注释在哪里?现在尝试一下,结果无效。我将其设置为私有,因为hibernate支持使用反射来填充属性,并且可以访问私有方法。(我也不希望任何爱管闲事的开发人员使用它;-))用注释编辑问题。