如题。。在网上搜了半天也找不到答案,希望大家能给点例子。只想问一点就是。
那句annotation语句该怎么写?有3种继承,1个是单表继承的,其他两个都是多表继承,3种类型分别该怎么写呢?不是EJB哦。普通hibernate@这里的内容
public class A{}
@还有这里的内容
public class B extends A{}

解决方案 »

  1.   


    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.MappedSuperclass;@MappedSuperclass
    public class IdEntity { private Long id; @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Long getId() {
    return id;
    } public void setId(Long id) {
    this.id = id;
    }
    }
    import java.util.LinkedHashSet;
    import java.util.List;
    import java.util.Set;import javax.persistence.CascadeType;
    import javax.persistence.Entity;
    import javax.persistence.JoinColumn;
    import javax.persistence.JoinTable;
    import javax.persistence.ManyToMany;
    import javax.persistence.OrderBy;
    import javax.persistence.Table;
    import javax.persistence.Transient;import org.apache.commons.lang.builder.ToStringBuilder;
    import org.hibernate.annotations.Cache;
    import org.hibernate.annotations.CacheConcurrencyStrategy;
    import com.zhjb.entity.IdEntity;
    import org.springside.modules.utils.CollectionUtils;@Entity
    @Table(name = "ROLES")
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    public class Role extends IdEntity { private String name; private Set<Authority> auths = new LinkedHashSet<Authority>(); public String getName() {
    return name;
    } public void setName(String name) {
    this.name = name;
    } @ManyToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
    @JoinTable(name = "ROLES_AUTHORITIES", joinColumns = { @JoinColumn(name = "ROLE_ID") }, inverseJoinColumns = { @JoinColumn(name = "AUTHORITY_ID") })
    @OrderBy("id")
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    public Set<Authority> getAuths() {
    return auths;
    } public void setAuths(Set<Authority> auths) {
    this.auths = auths;
    } @Transient
    public String getAuthNames() throws Exception {
    return CollectionUtils.fetchPropertyToString(auths, "displayName", ", ");
    } @SuppressWarnings("unchecked")
    @Transient
    public List<Long> getAuthIds() throws Exception {
    return CollectionUtils.fetchPropertyToList(auths, "id");
    } @Override
    public String toString() {
    return ToStringBuilder.reflectionToString(this);
    }
    }