如何将一个瞬态字段作为hibernate实体中地图的键?

时间:2015-04-20 06:36:49

标签: java hibernate dictionary hibernate-mapping

我需要一张商品地图,但我需要制作的商品' key'是短暂的,冬眠不能成为一个关键的'。我该怎么办?

@Entity
@AssociationOverrides({
        @AssociationOverride(name = "rela.city", 
                         joinColumns = @JoinColumn(name = "cityId")),
        @AssociationOverride(name = "rela.person", 
                         joinColumns = @JoinColumn(name = "id")),
        @AssociationOverride(name = "rela.social", 
                         joinColumns = @JoinColumn(name = "code")) })
public class Person implements java.io.Serializable {
    @EmbeddedId
    private RelationshipId rela = new RelationshipId();

    @Transient
    public String getCode(){
         return rela.getSocial().geCode();
    }
    ....
}

@Entity
public class City implements java.io.Serializable {
    @OneToMany(fetch = FetchType.LAZY, 
               mappedBy = "rela.city", cascade = CascadeType.ALL)
    @MapKey(name = "code")
    Map<String, Person> People = new HashMap<>();
    ....
}

正如您所看到的,我希望将代码作为地图的关键,但由于代码是暂时的,因此无法正常运行。

0 个答案:

没有答案