Entidade
@Entity
public class Estoque implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@OneToOne
private Produto produto;
private double total;
public Estoque(Produto produto) {
this.produto = produto;
}
}
DAO
@Repository
@Transactional
public class EstoqueDAO {
@PersistenceContext
private EntityManager manager;
public void criaEstoquePara(Produto produto) {
Estoque estoque = new Estoque(produto);
manager.merge(estoque);
}
}
Ao salvar a entidade acontece o seguinte erro:
SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/sistema] threw exception [Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement] with root cause
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'produto_id' cannot be null
Já verifiquei se o estoque.produto contém de fato o produto, gostaria de saber se estou mapeando corretamente.