Pessoal, estou utilizando EJB3+JPA e banco de dados MySQL e estou tendo problemas com mapeamento one-to-one entre as seguintes classes Projeto e Cliente. Minha classe projeto tem uma referência ao cliente. Ou seja, um projeto só pode ter um cliente. Na tabela Projeto do banco de dados existe uma chave estrangeira cliente_id que faz referencia ao id do cliente. E meu problema é que no momento de persistir o EJB não consegue pegar o id do Cliente para persistir e tenta persistir o objeto Cliente no banco de dados…
Minha classe Projeto:
@Entity
@Table(name = "projeto")
@JSONObject
public class Projeto implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
@JSONAttribute(profile = "BASICO")
private Integer id;
@Basic(optional = false)
@Column(name = "nome")
@JSONAttribute(profile = "BASICO")
private String nome;
@Basic(optional = false)
@JSONAttribute(profile = "BASICO")
@OneToOne
@JoinColumn(name = "cliente_id")
private Cliente cliente;
...
// gets e sets...
E a classe Cliente
@Entity
@Table(name = "cliente")
@JSONObject
public class Cliente implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
@JSONAttribute(profile = "BASICO")
private Integer id;
@Basic(optional = false)
@Column(name = "nome")
@JSONAttribute(profile = "BASICO")
private String nome;
...
//gets e sets
O erro obtido ao tentar persistir no banco é o seguinte:
type Exception report
message
descriptionThe server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: javax.ejb.EJBException: Transaction aborted
root cause
javax.ejb.EJBException: Transaction aborted
root cause
javax.transaction.RollbackException: Transaction marked for rollback.
root cause
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column ‘CLIENTE’ in 'field list’
Error Code: 1054
Call: INSERT INTO projeto (data_fim, CLIENTE, data_inicio, nome) VALUES (?, ?, ?, ?)
bind => [2010-11-18 00:00:00.0, [B@17b2615, 2010-08-19 00:00:00.0, hiuashudsa]
Query: InsertObjectQuery(tno.tadm.model.entities.Projeto[id=null])
root cause
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column ‘CLIENTE’ in ‘field list’
É possível notar algum erro no mapeamento @OneToOne???