2014-01-21 2 views
1

내 개체를 초기화 할 때 GeneratedValue 주석을 사용하는 방법에 대한 모든 문서를 찾을 수없는 것 같습니다. 여기@GeneratedValue 주석, 생성자 값

내 개체 클래스 내 id 필드, 나는 두 개의 다른 분야 나는

@Id 
@GeneratedValue(strategy = GenerationType.IDENTITY) 
@Basic(optional = false) 
@NotNull 
@Column(name = "ID") 
private BigDecimal id; 

내 생성자

public Pothole() { 
} 

public Pothole(BigDecimal id) { 
    this.id = id; 
} 

public Pothole(BigDecimal id, byte[] image, Date pdate) { 
    this.id = id; 
    this.image = image; 
    this.pdate = pdate; 
} 

내 ID 필드에 무엇을 사용합니까을 떠난 한 된 ?? 주어진 개체의 id 데이터베이스에 의해 평가 될 것이다 (즉, insert 문을 수행) 나는 Hibernate가 데이터베이스에서 엔티티를 지속 할 때 빈

Pothole entity = new Pothole(???,decodedBytes, date); 

답변

0

예, 빈을 떠나해야 떠나 마십시오 (귀하의 경우 ID 열에 값이 제공됩니다). "d` 속성은 엔티티가 지속될 때까지 비어 있습니다. 기본 생성자를 사용

0

Pothole entity = new Pothole(); 
    entity.setImage(decodedBytes); 
    entity.setPdate(date); 
근무