How to map java-field to db-field in ManyToOne?
Hello guys!I got a question about a mapping between a entity class and a table, I use with hibernate.
The table looks like:
CREATE TABLE ProductComments
(
id BIGINT NOT NULL AUTO_INCREMENT,
parentProductComment_id BIGINT,
text VARCHAR(1024) NOT NULL,
PRIMARY KEY(id),
CONSTRAINT ProductComments_ProductComments FOREIGN KEY(parentProductComment_id) REFERENCES ProductComments (id)
ON DELETE CASCADE
ON UPDATE CASCADE
) ENGINE=InnoDB;
The class looks like:
@Entity
@Table(name = "ProductComments")
public class ProductComment implements Serializable
{
@Id
@GeneratedValue
private String id;
private String text;
@ManyToOne
private ProductComment parentProductComment;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text.trim();
}
public ProductComment getParentProductComment() {
return parentProductComment;
}
public void setParentProductComment(ProductComment parentProductComment) {
this.parentProductComment = parentProductComment;
}
}
The problem is that I would like the field "parentProductComment_id" in the databse be called "fk_parentProductCommentId".
But I would like the entity class be as it is.
I guess in some how it must be possible to tell the @ManyToOne to use a certain column with a certain name, but I can not find out how.
Best regards
Fredrik
