I have a class hierarchy:
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:
Thanks
Okay here's how I ended up solving the problem:
Base class:
@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
}
Descendant class:
@Entity
@SequenceGenerator(name="SEQ",sequenceName="SEQ_DB_NAME")
public class BusinessObject extends DomainObject {
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With