问题描述
我将以下数据插入到HSQL中:
INSERT INTO Consumer(id,ConsumerId,CREATEDBY,CREATEDAT,FK_Service,ConsumerType) VALUES(300,'adsgvcg-cvvce-hvchwec','sm',CURRENT_TIMESTAMP,1,'INTERNAL');
我有以下从表中读取的类:
Entity(name = "Consumer")
@Table(name = "Consumer")
public class Consumer extends Base {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name = "ID")
private long id;
@Basic(optional = false)
@Column(name = "ConsumerId", nullable = false)
private String ConsumerId;
@Basic(optional = false)
@Column(name = "ConsumerType", nullable = false)
private String ConsumerType;
@Basic//(optional = false)
@Column(name = "FK_Service", nullable = true)
private String service;
//Getter Setters etc
和基类看起来像:
public class Base implements Serializable{
@Basic
@Column(name = "MODIFIEDBY", nullable = true)
private String ModifiedBy;
@Basic
@Column(name = "MODIFIEDAT", nullable = true)
private Timestamp ModifiedAt;
@Basic
@Column(name = "CREATEDBY", nullable = true)
private String CreatedBy;
@Basic
@Column(name = "CREATEDAT", nullable = true)
private Timestamp CreatedAt;
//Getter Setters etc
运行代码时,出现以下异常:
2015-07-25 22:21:12,875 ERROR [main] hbm2ddl.SchemaExport.? (?:?) - HHH000388: Unsuccessful: INSERT INTO Consumer(id,ConsumerId,CREATEDBY,CREATEDAT,FK_Service,ConsumerType) VALUES(300,'adsgvcg-cvvce-hvchwec','smenon2',CURRENT_TIMESTAMP,1,'INTERNAL')
2015-07-25 22:21:12,875 ERROR [main] hbm2ddl.SchemaExport.? (?:?) - user lacks privilege or object not found: CREATEDBY
但是,当我将字段从基类移到父(消费者)类时,将不再发生此异常,并且字段也将被填充。
1楼
您需要在hibernate中使用在基本实体中,您需要添加注释,以便hibernate知道要使用哪种策略。
@MappedSuperclass
要么
@Inhertitance(strategy = InheritanceType.SINGLE_TABLE)可以使用以下策略之一:
- InheritanceType.SINGLE_TABLE
- InheritanceType.TABLE_PER_CLASS
- InheritanceType.JOINED
该可能会有所帮助。