你好,我是个新手。 我正在使用spring jpa hibernate制作自己的应用程序。 我有一个实体类,它通常可以工作,但是会出现属性重复的问题。 我的代码看起来像这样:
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.validation.constraints.NotNull;
@Entity
public class Event {
@Id
@GeneratedValue
private Integer id;
public Integer getId() {
return id;
}
@Column(nullable = false)
public void setId(Integer id) {
this.id = id;
}
/*------------------------------ title ------------------------*/
private String title;
@Column(nullable = false)
public String getTitle() {
return title;
}
@Column(nullable = false)
public void setTitle(String title) {
this.title = title;
}
/* [Note] I have two extra ids : event_id, eventId
- so these are not the case of the duplication. */
/*------------------- event_id -----------------------------*/
private String event_id;
public String getEvent_id() {
return event_id;
}
public void setEvent_id(String event_id) {
this.event_id = event_id;
}
/*-------------- eventId -------------------------------------*/
@Column(unique = true)
private String eventId;
public String getEventId() {
return eventId;
}
public void setEventId(String eventId) {
this.eventId = eventId;
}
/*------------------------------ publishedDate ------------------------------------------*/
private String publishedDate;
public String getPublishedDate() {
return publishedDate;
}
@Column(nullable = false)
public void setPublishedDate(String publishedDate) {
this.publishedDate = publishedDate;
}
/*--------------------------------- endTime -----------------------------------*/
private String endTime;
public String getEndTime() {
return endTime;
}
@Column(nullable = false)
public void setEndTime(String endTime) {
this.endTime = endTime;
}
/*-------------------------------- user ------------------------------------------*/
@ManyToOne
@JoinColumn(name="user_id")
private User user;
public User getUser() {
return user;
}
@Column(nullable = false)
public void setUser(User user) {
this.user = user;
}
当我查看JPA图表时,发现有多个属性重复出现。我在下面添加了我的JPA图像(红色部分为重复项):
这是我第一次使用Java编程开发应用程序,请谅解。即使我已经阅读了Spring JPA的文档,也很难找出代码中到底哪里出错了。您有什么想法吗?提前感谢。
@Column(nullable = false) public String getTitle() { return title; }
。这是否意味着“在getter方法上放置注解”?所以我应该删除所有getxxx、setxxxx上的@Column...
吗? - user1915570