我有一个类层次结构:
abstract DomainObject {
...
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="SEQ")
@SequenceGenerator(name="SEQ",sequenceName="SEQ_DB_NAME")
@Column(name = "id", updatable = false, nullable = false)
private Long id;
...
}
BaseClass extends DomainObject {
...
// Fill in blank here where this class's @Id will use a unique sequence generator
// bonus points for any sort of automatic assignment of generator names that might
//prevent me from having to instrument all my domain objects uniquely
...
}
notes:
- 我并不特别需要基类生成器,因此如果我需要删除它也没有问题。
- 这是一个 oracle 9i db(如果适用)
- 休眠 3.4 JPA
- Spring 2.5 也可用
Thanks
好的,这就是我最终解决问题的方法:
基类:
@MappedSuperclass
public abstract class DomainObject implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="SEQ")
@Column(name = "id", updatable = false, nullable = false)
private Long id;
.. rest of class
}
后代类:
@Entity
@SequenceGenerator(name="SEQ",sequenceName="SEQ_DB_NAME")
public class BusinessObject extends DomainObject {
...
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)