[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.rt.eclipselink] MySQL Autoinc FK

I have two entities :

Pessoa :

// Data Defination

CREATE TABLE  `pessoa` (
 `ID_PESSOA` int(11) NOT NULL AUTO_INCREMENT,
 `NO_PESSOA` varchar(80)  NOT NULL,
 PRIMARY KEY (`ID_PESSOA`)
) ENGINE=InnoDB ;


@Entity
@Table(name = "pessoa")
public class Pessoa implements Serializable {
private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "ID_PESSOA")
private Integer idPessoa;
@Basic(optional = false)
@Column(name = "NO_PESSOA")
private String noPessoa;
@OneToOne(cascade = CascadeType.ALL, mappedBy = "pessoa", fetch = FetchType.LAZY)
private PessoaFisica pessoaFisica;




PessoaFisica :

// Data Defination

CREATE TABLE `pessoa_fisica` (
`ID_PESSOA` int(11) NOT NULL,
`NR_CPF` char(11) COLLATE utf8_unicode_ci DEFAULT NULL,
`id_ESTADO_CIVIL` smallint(6) DEFAULT NULL,
`dt_nascimento` date DEFAULT NULL,
PRIMARY KEY (`ID_PESSOA`),
KEY `NR_CPF` (`NR_CPF`),
KEY `fk_pessoa_fisica_pessoa` (`ID_PESSOA`),
CONSTRAINT `fk_pessoa_fisica_pessoa` FOREIGN KEY (`ID_PESSOA`) REFERENCES `pessoa` (`ID_PESSOA`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB ;



@Entity
@Table(name = "pessoa_fisica")
public class PessoaFisica implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@Column(name = "ID_PESSOA")
private Integer idPessoa;
@Column(name = "NR_CPF")
private String nrCpf;
@Column(name = "id_ESTADO_CIVIL")
private Short idESTADOCIVIL;
@Column(name = "dt_nascimento")
@Temporal(TemporalType.DATE)
private Date dtNascimento;
@JoinColumn(name = "ID_PESSOA", referencedColumnName = "ID_PESSOA", insertable = false, updatable = false)
@OneToOne(optional = false, fetch = FetchType.LAZY)
private Pessoa pessoa;




While persisting Pessoa I am getting following error :

SEVERE: >>javax.persistence.RollbackException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 1.1.0.r3634): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'ID_PESSOA' cannot be null
Error Code: 1048
Call: INSERT INTO pessoa_fisica (ID_PESSOA, id_ESTADO_CIVIL, dt_nascimento, NR_CPF) VALUES (?, ?, ?, ?)
bind => [null, 1, 2009-06-16, 001.797.717-79]
Query: InsertObjectQuery(br.com.mecsoft.imobiliario.model.PessoaFisica[idPessoa=null])
org.eclipse.persistence.exceptions.DatabaseException:
Internal Exception: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'ID_PESSOA' cannot be null
Error Code: 1048
Call: INSERT INTO pessoa_fisica (ID_PESSOA, id_ESTADO_CIVIL, dt_nascimento, NR_CPF) VALUES (?, ?, ?, ?)
bind => [null, 1, 2009-06-16, 001.797.717-79]
Query: InsertObjectQuery(br.com.mecsoft.imobiliario.model.PessoaFisica[idPessoa=null])
[SQL: 1048, 23000]
com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column
'ID_PESSOA' cannot be null
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:931)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2870)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)
at
com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1169)
at
com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:693)
...