Olá,
estou tendo problemas para persistir uma clase aqui, por favor olhem, e me digam o que há de errado.
O erro que esta dando é:
[TopLink Warning]: 2009.06.27 07:42:48.478--UnitOfWork(1814208212)--Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Cannot insert the value NULL into column 'codVenda', table 'TrabalhoJava.dbo.ItemVenda'; column does not allow nulls. INSERT fails.
Error Code: 515
Call: INSERT INTO ITEMVENDA (valTotal, qtdItemVenda, codVenda, codProd) VALUES (?, ?, ?, ?)
bind => [30.0, 2, null, 1]
Query: InsertObjectQuery(br.com.trabalho.model.ItemVenda[codItemVenda=null])
Exception in thread "AWT-EventQueue-0" javax.persistence.RollbackException: Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Cannot insert the value NULL into column 'codVenda', table 'TrabalhoJava.dbo.ItemVenda'; column does not allow nulls. INSERT fails.
Error Code: 515
Call: INSERT INTO ITEMVENDA (valTotal, qtdItemVenda, codVenda, codProd) VALUES (?, ?, ?, ?)
bind => [30.0, 2, null, 1]
Query: InsertObjectQuery(br.com.trabalho.model.ItemVenda[codItemVenda=null])
at oracle.toplink.essentials.internal.ejb.cmp3.transaction.base.EntityTransactionImpl.commit(EntityTransactionImpl.java:120)
at oracle.toplink.essentials.internal.ejb.cmp3.transaction.EntityTransactionImpl.commit(EntityTransactionImpl.java:60)
at br.com.trabalho.dao.TrabalhoJavaDAO.gravaVenda(TrabalhoJavaDAO.java:73)
at br.com.trabalho.ctrl.VendaCTR.gravaVenda(VendaCTR.java:100)
at br.com.trabalho.ctrl.VendaCTR.update(VendaCTR.java:120)
at java.util.Observable.notifyObservers(Observable.java:142)
at java.util.Observable.notifyObservers(Observable.java:98)
at br.com.trabalho.model.Principal.setComando(Principal.java:22)
at br.com.trabalho.view.VendasVIEW.jbtSalvarActionPerformed(VendasVIEW.java:434)
at br.com.trabalho.view.VendasVIEW.access$1000(VendasVIEW.java:12)
at br.com.trabalho.view.VendasVIEW$12.actionPerformed(VendasVIEW.java:273)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6263)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Caused by: Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Cannot insert the value NULL into column 'codVenda', table 'TrabalhoJava.dbo.ItemVenda'; column does not allow nulls. INSERT fails.
Error Code: 515
Call: INSERT INTO ITEMVENDA (valTotal, qtdItemVenda, codVenda, codProd) VALUES (?, ?, ?, ?)
bind => [30.0, 2, null, 1]
Query: InsertObjectQuery(br.com.trabalho.model.ItemVenda[codItemVenda=null])
at oracle.toplink.essentials.exceptions.DatabaseException.sqlException(DatabaseException.java:311)
at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:654)
at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.executeNoSelect(DatabaseAccessor.java:703)
at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:492)
at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:452)
at oracle.toplink.essentials.internal.sessions.AbstractSession.executeCall(AbstractSession.java:690)
at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:228)
at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:214)
at oracle.toplink.essentials.internal.queryframework.DatasourceCallQueryMechanism.insertObject(DatasourceCallQueryMechanism.java:346)
at oracle.toplink.essentials.internal.queryframework.StatementQueryMechanism.insertObject(StatementQueryMechanism.java:191)
at oracle.toplink.essentials.internal.queryframework.StatementQueryMechanism.insertObject(StatementQueryMechanism.java:205)
at oracle.toplink.essentials.internal.queryframework.DatabaseQueryMechanism.insertObjectForWrite(DatabaseQueryMechanism.java:564)
at oracle.toplink.essentials.queryframework.InsertObjectQuery.executeCommit(InsertObjectQuery.java:89)
at oracle.toplink.essentials.internal.queryframework.DatabaseQueryMechanism.performUserDefinedWrite(DatabaseQueryMechanism.java:750)
at oracle.toplink.essentials.internal.queryframework.DatabaseQueryMechanism.performUserDefinedInsert(DatabaseQueryMechanism.java:714)
at oracle.toplink.essentials.internal.queryframework.DatabaseQueryMechanism.insertObjectForWriteWithChangeSet(DatabaseQueryMechanism.java:602)
at oracle.toplink.essentials.queryframework.WriteObjectQuery.executeCommitWithChangeSet(WriteObjectQuery.java:162)
at oracle.toplink.essentials.internal.queryframework.DatabaseQueryMechanism.executeWriteWithChangeSet(DatabaseQueryMechanism.java:390)
at oracle.toplink.essentials.queryframework.WriteObjectQuery.executeDatabaseQuery(WriteObjectQuery.java:109)
at oracle.toplink.essentials.queryframework.DatabaseQuery.execute(DatabaseQuery.java:628)
at oracle.toplink.essentials.queryframework.DatabaseQuery.executeInUnitOfWork(DatabaseQuery.java:555)
at oracle.toplink.essentials.queryframework.ObjectLevelModifyQuery.executeInUnitOfWorkObjectLevelModifyQuery(ObjectLevelModifyQuery.java:138)
at oracle.toplink.essentials.queryframework.ObjectLevelModifyQuery.executeInUnitOfWork(ObjectLevelModifyQuery.java:110)
at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2233)
at oracle.toplink.essentials.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:952)
at oracle.toplink.essentials.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:909)
at oracle.toplink.essentials.internal.sessions.CommitManager.commitNewObjectsForClassWithChangeSet(CommitManager.java:269)
at oracle.toplink.essentials.internal.sessions.CommitManager.commitAllObjectsForClassWithChangeSet(CommitManager.java:246)
at oracle.toplink.essentials.internal.sessions.CommitManager.commitAllObjectsWithChangeSet(CommitManager.java:202)
at oracle.toplink.essentials.internal.sessions.AbstractSession.writeAllObjectsWithChangeSet(AbstractSession.java:2657)
at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.commitToDatabase(UnitOfWorkImpl.java:1044)
at oracle.toplink.essentials.internal.ejb.cmp3.base.RepeatableWriteUnitOfWork.commitToDatabase(RepeatableWriteUnitOfWork.java:403)
at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.commitToDatabaseWithChangeSet(UnitOfWorkImpl.java:1126)
at oracle.toplink.essentials.internal.ejb.cmp3.base.RepeatableWriteUnitOfWork.commitRootUnitOfWork(RepeatableWriteUnitOfWork.java:107)
at oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.commitAndResume(UnitOfWorkImpl.java:856)
at oracle.toplink.essentials.internal.ejb.cmp3.transaction.base.EntityTransactionImpl.commit(EntityTransactionImpl.java:102)
... 35 more
Caused by: java.sql.SQLException: Cannot insert the value NULL into column 'codVenda', table 'TrabalhoJava.dbo.ItemVenda'; column does not allow nulls. INSERT fails.
at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:368)
at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2816)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2254)
at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:631)
at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:584)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:546)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeUpdate(JtdsPreparedStatement.java:505)
at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:647)
... 69 more
As minha clases Venda e Itemvenda:
[code]package br.com.trabalho.model;
import java.io.Serializable;
import javax.persistence.*;
@Entity
@Table(name=“ItemVenda”)
public class ItemVenda implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name = "codItemVenda",nullable=false,length=4)
private Integer codItemVenda;
@Column(name = "qtdItemVenda",nullable=false)
private int qtdItemVenda;
@Column(name = "valTotal",nullable=false)
private Double valTotal;
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name = "codProd", referencedColumnName = "codProd")
private Produto produto;
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name = "codVenda", referencedColumnName = "codVenda")
private Venda codVenda;
public ItemVenda() {
}
public ItemVenda(Integer codItemVenda) {
this.codItemVenda = codItemVenda;
}
public ItemVenda(Produto produto, Integer qtd) {
this.produto = produto;
this.qtdItemVenda = qtd;
this.valTotal = this.qtdItemVenda*produto.getPrecoProd();
}
public Integer getCodItemVenda() {
return codItemVenda;
}
public void setCodItemVenda(Integer codItemVenda) {
this.codItemVenda = codItemVenda;
}
public int getQtdItemVenda() {
return qtdItemVenda;
}
public void setQtdItemVenda(int qtdItemVenda) {
this.qtdItemVenda = qtdItemVenda;
}
public Double getValTotal() {
return valTotal;
}
public void setValTotal(Double valTotal) {
this.valTotal = valTotal;
}
public Venda getCodVenda() {
return codVenda;
}
public void setCodVenda(Venda codVenda) {
this.codVenda = codVenda;
}
@Override
public int hashCode() {
int hash = 0;
hash += (codItemVenda != null ? codItemVenda.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof ItemVenda)) {
return false;
}
ItemVenda other = (ItemVenda) object;
if ((this.codItemVenda == null && other.codItemVenda != null) || (this.codItemVenda != null && !this.codItemVenda.equals(other.codItemVenda))) {
return false;
}
return true;
}
@Override
public String toString() {
return "br.com.trabalho.model.ItemVenda[codItemVenda=" + codItemVenda + "]";
}
public Produto getProduto() {
return produto;
}
public void setProduto(Produto produto) {
this.produto = produto;
}
}[/code]
[code]import java.io.Serializable;
import java.util.;
import javax.persistence.;
@Entity
@Table(name=“Venda”)
public class Venda implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name = "codVenda",nullable=false)
private Integer codVenda;
@Column(name = "datVenda",nullable=false)
@Temporal(TemporalType.TIMESTAMP)
private Date datVenda = new Date();
@Column(name = "totalVenda",nullable=false)
private Double totalVenda;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "codCli", referencedColumnName = "codCli")
private Cliente cliente;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "codVenda")
private List<ItemVenda> itensVenda;
public Venda() {
}
public Integer getCodVenda() {
return codVenda;
}
public void setCodVenda(Integer codVenda) {
this.codVenda = codVenda;
}
public Date getDatVenda() {
return datVenda;
}
public void setDatVenda(Date datVenda) {
this.datVenda = datVenda;
}
public Double getTotalVenda() {
return totalVenda;
}
public void setTotalVenda(Double totalVenda) {
this.totalVenda = totalVenda;
}
@Override
public int hashCode() {
int hash = 0;
hash += (codVenda != null ? codVenda.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Venda)) {
return false;
}
Venda other = (Venda) object;
if ((this.codVenda == null && other.codVenda != null) || (this.codVenda != null && !this.codVenda.equals(other.codVenda))) {
return false;
}
return true;
}
@Override
public String toString() {
return "br.com.trabalho.model.Venda[codVenda=" + codVenda + "]";
}
/**
* @return the itensVenda
*/
public List<ItemVenda> getItensVenda() {
return itensVenda;
}
/**
* @param itensVenda the itensVenda to set
*/
public void setItensVenda(List<ItemVenda> itensVenda) {
this.itensVenda = itensVenda;
}
/**
* @return the cliente
*/
public Cliente getCliente() {
return cliente;
}
/**
* @param cliente the cliente to set
*/
public void setCliente(Cliente cliente) {
this.cliente = cliente;
}
}[/code]