How would you configure annotations in the following example code? I'd like to stick with JPA annotations only and avoid Hibernate specific dependencies. Is the code below correct?
@Entity
public class RefExample extends RefData {
}
(There will be multiple versions of these classes, RefSomeOtherExample, etc, and one db table per class. Some may add additional fields (columns) but most will simply make use of the basic fields inherited from the "RefData" base class.)
Base class:
@Entity
public abstract class RefData {
private long id;
private String code;
private String desc;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(unique = true, nullable = false)
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
@Column(unique = true, nullable = false, length=8)
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
@Column(unique = true, nullable = false, length=80)
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
}
Ultimately I'd like to generate schema creation scripts from this using Hibernate's SchemaExport class. In the case above these two classes should only result in the creation of a single table named "RefExample" with the three columns from "RefData". Will this work?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…