Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Hibernate@Filter未应用于关联_Java_Hibernate_Hibernate Mapping - Fatal编程技术网

Java Hibernate@Filter未应用于关联

Java Hibernate@Filter未应用于关联,java,hibernate,hibernate-mapping,Java,Hibernate,Hibernate Mapping,我无法理解为什么我的筛选器未应用于关联 我可以看到它正在注册 06 Mar 2014 02:55:33,039 [INFO] (main) org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean: Building new Hibernate SessionFactory 06 Mar 2014 02:55:33,039 [DEBUG] (main) org.hibernate.cfg.Config

我无法理解为什么我的筛选器未应用于关联

我可以看到它正在注册

06 Mar 2014 02:55:33,039 [INFO]  (main) org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean: Building new Hibernate SessionFactory
06 Mar 2014 02:55:33,039 [DEBUG]  (main) org.hibernate.cfg.Configuration: Preparing to build session factory with filters : {addressType=org.hibernate.engine.FilterDefinition@1015ee3d}
06 Mar 2014 02:55:40,172 [DEBUG]  (main) org.hibernate.impl.SessionFactoryImpl: Session factory constructed with filter configurations : {addressType=org.hibernate.engine.FilterDefinition@1015ee3d}
下面是我的班级

@Entity
@Table(name = "person")
@FilterDef(name = "addressType", parameters = @ParamDef(name = "addressType", type = "string"))
public class Person {

    @Id
    @Column(name = "EMPLID", nullable = false)
    private String employeeId;

    @OneToMany
    @JoinColumn(name = "EMPLID")
    @Filter(name = "addressType", condition = ":addressType = ADDRESS_TYPE")
    private Set<PersonAddressHistory> personAddressHistories;

    public String getEmployeeId() {
        return employeeId;
    }

    public void setEmployeeId(final String employeeId) {
        this.employeeId = employeeId;
    }


    public Set<PersonAddressHistory> getPersonAddressHistories() {
        return personAddressHistories;
    }

    public void setPersonAddressHistories(final Set<PersonAddressHistory> personAddressHistories) {
        this.personAddressHistories = personAddressHistories;
    }

    @Override
    public String toString() {
        return Objects.toStringHelper(this).add("employeeId", getEmployeeId()).toString();
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (!(obj instanceof Person)) {
            return false;
        }
        Person other = (Person) obj;

        return Objects.equal(getEmployeeId(), other.getEmployeeId());
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(getEmployeeId());
    }

}


@Entity
@Table(name = "address_history")
public class PersonAddressHistory implements Serializable {

    @Column(name = "EMPLID", nullable = false)
    private String employeeId;

    @Id
    @Column(name = "ADDRESS_TYPE", nullable = false)
    private String addressType;

    @Id
    @Column(name = "EFFDT", nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Calendar effectiveDate;

    @Embedded
    @AttributeOverrides({
            @AttributeOverride(name = "addressLine1", column = @Column(name = "ADDRESS", nullable = false)),
            @AttributeOverride(name = "city", column = @Column(name = "CITY", nullable = false)),
            @AttributeOverride(name = "state", column = @Column(name = "STATE", nullable = false)),
            @AttributeOverride(name = "country", column = @Column(name = "COUNTRY", nullable = false)),
            @AttributeOverride(name = "postalCode", column = @Column(name = "POSTAL", nullable = false)) })
    private Address address;

    public String getEmployeeId() {
        return employeeId;
    }

    public void setEmployeeId(final String employeeId) {
        this.employeeId = employeeId;
    }

    public String getAddressType() {
        return addressType;
    }

    public void setAddressType(final String addressType) {
        this.addressType = addressType;
    }

    public Calendar getEffectiveDate() {
        return effectiveDate;
    }

    public void setEffectiveDate(final Calendar effectiveDate) {
        this.effectiveDate = effectiveDate;
    }

    public Address getAddress() {
        return address;
    }

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

    @Override
    public String toString() {
        return Objects.toStringHelper(this).add("employeeId", getEmployeeId()).add("addressType", getAddressType())
                .add("address", getAddress())
                .toString();
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (!(obj instanceof PersonAddressHistory)) {
            return false;
        }
        PersonAddressHistory other = (PersonAddressHistory) obj;

        return Objects.equal(getEmployeeId(), other.getEmployeeId())
                && Objects.equal(getAddressType(), other.getAddressType())
                && Objects.equal(getEffectiveDate(), other.getEffectiveDate());
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(getEmployeeId(), getAddressType(), getEffectiveDate());
    }

}

And in my DAO

public class PersonDao extends AbstractBaseDao {

    public Person getPersonById(final String id) {
        getCurrentSession().enableFilter("addressType").setParameter("addressType", "HOME");
        return (Person) getCurrentSession().get(Person.class, id);
    }

}
@实体
@表(name=“person”)
@FilterDef(name=“addressType”,parameters=@ParamDef(name=“addressType”,type=“string”))
公共阶层人士{
@身份证
@列(name=“EMPLID”,nullable=false)
私有字符串employeeId;
@独身癖
@JoinColumn(name=“EMPLID”)
@过滤器(name=“addressType”,条件=“:addressType=地址类型”)
私人设置的个人地址历史记录;
公共字符串getEmployeeId(){
返回员工ID;
}
public void setEmployeeId(最终字符串employeeId){
this.employeeId=employeeId;
}
公共集GetPersonalAddressHistories(){
返回个人地址历史记录;
}
public void setPersonalAddressHistories(最终设置PersonalAddressHistories){
this.PersonalAddressHistories=PersonalAddressHistories;
}
@凌驾
公共字符串toString(){
返回Objects.toString.Helper(this.add(“employeeId”,getEmployeeId()).toString();
}
@凌驾
公共布尔等于(对象obj){
if(this==obj){
返回true;
}
if(obj==null){
返回false;
}
如果(!(人的obj实例)){
返回false;
}
人员其他=(人员)obj;
返回Objects.equal(getEmployeeId(),other.getEmployeeId());
}
@凌驾
公共int hashCode(){
返回Objects.hashCode(getEmployeeId());
}
}
@实体
@表(name=“地址\历史记录”)
公共类PersonalAddressHistory实现可序列化{
@列(name=“EMPLID”,nullable=false)
私有字符串employeeId;
@身份证
@列(name=“ADDRESS\u TYPE”,null=false)
私有字符串地址类型;
@身份证
@列(name=“EFFDT”,nullable=false)
@时态(TemporalType.TIMESTAMP)
私人日历生效日期;
@嵌入
@属性溢出({
@AttributeOverride(name=“addressLine1”,column=@column(name=“ADDRESS”,nullable=false)),
@AttributeOverride(name=“city”,column=@column(name=“city”,nullable=false)),
@AttributeOverride(name=“state”,column=@column(name=“state”,nullable=false)),
@AttributeOverride(name=“country”,column=@column(name=“country”,nullable=false)),
@AttributeOverride(name=“postalCode”,column=@column(name=“POSTAL”,nullable=false))})
私人地址;
公共字符串getEmployeeId(){
返回员工ID;
}
public void setEmployeeId(最终字符串employeeId){
this.employeeId=employeeId;
}
公共字符串getAddressType(){
返回地址类型;
}
public void setAddressType(最终字符串addressType){
this.addressType=addressType;
}
公共日历getEffectiveDate(){
返回生效日期;
}
公共作废设置生效日期(最终日历生效日期){
this.effectiveDate=effectiveDate;
}
公共广播getAddress(){
回信地址;
}
公共无效设置地址(最终地址){
this.address=地址;
}
@凌驾
公共字符串toString(){
返回Objects.toString.Helper(this.add(“employeeId”,getEmployeeId()).add(“addressType”,getAddressType())
.add(“地址”,getAddress())
.toString();
}
@凌驾
公共布尔等于(对象obj){
if(this==obj){
返回true;
}
if(obj==null){
返回false;
}
if(!(人物地址历史的obj实例)){
返回false;
}
PersonalAddressHistory其他=(PersonalAddressHistory)obj;
返回Objects.equal(getEmployeeId(),other.getEmployeeId())
&&Objects.equal(getAddressType(),other.getAddressType())
&&Objects.equal(getEffectiveDate(),other.getEffectiveDate());
}
@凌驾
公共int hashCode(){
返回Objects.hashCode(getEmployeeId(),getAddressType(),getEffectiveDate());
}
}
在我的刀里
公共类PersonDao扩展了AbstractBaseDao{
公众人物getPersonById(最终字符串id){
getCurrentSession().enableFilter(“addressType”).setParameter(“addressType”,“HOME”);
return(Person)getCurrentSession().get(Person.class,id);
}
}
我正在使用遗留模式。 另外,如果要在java.util.Calendar实例上进行筛选,那么在hibernate@FilterDef注释-“java.util.Calendar”或“Calendar”中指定什么作为参数类型


非常感谢。请尝试更改FilterDef的注释,将其移动到类PersonalAddressHistory:

@Entity 
@Table(name = "person") 
@FilterDef(name = "addressType", parameters = @ParamDef(name = "addressType", type = "java.lang.String")) 
public class PersonAddressHistory implements Serializable {