Hibernate创建空的" ID"代码中的列,如本文所述。
如何调整它以不创建" ID"列(" ID"是创建列的确切名称)或者这不能更改?
@Entity
@Table(name = "CATEGORY_RELATIONS")
public class CategoryRelations implements Serializable {
private CategoryRelationsPrimaryKey id;
@Id
@Column(name = "CATEGORY_RELATIONS_CATEGORY_ID")
private String categoryId;
@Id
@Column(name = "CATEGORY_RELATIONS_PARENT_ID")
private String parentId;
//getters and setters
@Entity
@IdClass(CategoryRelationsPrimaryKey.class)
public class CategoryRelationsPrimaryKey implements Serializable {
protected long categoryId;
protected long parentId;
//euqals, hashCode
}
}
答案 0 :(得分:0)
1)@IdClass
应该站在实体,而不是复合id类;
2)如果您已按@Id
标记了ID属性,则不需要单独的id
属性:
@Entity
@Table(name = "CATEGORY_RELATIONS")
@IdClass(CategoryRelationsPrimaryKey.class)
public class CategoryRelations implements Serializable {
@Id
@Column(name = "CATEGORY_RELATIONS_CATEGORY_ID")
private String categoryId;
@Id
@Column(name = "CATEGORY_RELATIONS_PARENT_ID")
private String parentId;
//...
}
public class CategoryRelationsPrimaryKey implements Serializable {
protected String categoryId;
protected String parentId;
// ...
}
如果您需要一些名为id
的属性,请将其设为transient
以避免映射到数据库表列。