These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Problems: Swing and Hibernate
PostPosted: Tue Feb 15, 2011 11:02 pm 
Newbie

Joined: Tue Feb 15, 2011 10:40 pm
Posts: 1
Hello everybody!

I'm having problems inserting data from one form to a database.
I am using hibernate, and I can not insert a value returned from another table.

These are POJOs:

BancoBean.java

Code:
@Entity
@Table(name="tb_banco")
public class BancoBean implements Serializable{

/** Declarações **/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "bc_id", nullable=false)
private Integer bcId;
@Column(name = "bc_banco", length=50)
private String bcBanco;
@Column(name = "bc_agencia", length=4)
private Integer bcAgencia;
@Column(name = "bc_num_conta", length=5)
private Integer bcNumConta;
@OneToMany(mappedBy = "cxBanco")
private Collection<TbCaixa> tbCaixaCollection;

// getters and setters


PlanoDeContasBean.java

Code:
@Entity
@Table(name="tb_plano_de_contas")
public class PlanoDeContasBean implements java.io.Serializable {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "pc_id")
private Integer pcId;
@Column(name = "pc_conta")
private String pcConta;
@Column(name = "pc_natureza")
private String pcNatureza;
@OneToMany(mappedBy = "cxPlanoDeContas")
private Collection<TbCaixa> tbCaixaCollection;

/** getters and setters */


CaixaBean.java

Code:
@Entity
@Table(name="tb_caixa")
public class CaixaBean implements Serializable{

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "cx_n_doc", nullable=false)
private Integer cxNDoc;
@Column(name = "cx_local")
private String cxLocal;
@Column(name = "cx_data")
@Temporal(TemporalType.DATE)
private Date cxData;
@Column(name = "cx_tipo_lancamento")
private String cxTipoLancamento;
@Column(name = "cx_historico")
private String cxHistorico;
@Column(name = "cx_valor")
private Double cxValor;
@JoinColumn(name = "cx_banco", referencedColumnName = "bc_id")
@ManyToOne
private BancoBean cxBanco;
@JoinColumn(name = "cx_plano_de_contas", referencedColumnName = "pc_id")
@ManyToOne
private PlanoDeContasBean cxPlanoDeContas;

// getters and setters


I only use one class with generics for the manipulation of the data:

Control.java

Code:
public class Control<C> implements ControlInterface{

private C c;
private final Session session;
/** Creates a new instance of Control */
public Control(C c) {
this.session = HibernateUtil.getInstance().getSession();
this.c = c;
}

public void salva() {
try{
session.save(c);
session.getTransaction().commit();
}catch (HibernateException he){

}
}

public void altera() {
try{
session.update(c);
session.getTransaction().commit();
}catch (HibernateException he){

}
}

public void exclui() {
try{
session.delete(c);
session.getTransaction().commit();
}catch (HibernateException he){

}
}

public List<?> listaTudo() {
Criteria criteria = session.createCriteria(c.getClass());
List<?> list = criteria.list();
session.beginTransaction().commit();

return list;
}

}

I've already got the forms to enter data in the entities and PlanoDeContasBean BancoBean, but I could not CaixaBean entity.
Code:
private void salvaButtonActionPerformed(java.awt.event.ActionEvent evt) {
CaixaBean caixa = new CaixaBean();
Control control = new Control(caixa);

List<PlanoDeContasBean> planos;

SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
Date data;
try {
data = (Date) formatter.parse(txtData.getText());

caixa.setCxLocal(txtLocal.getText().toUpperCase());
caixa.setCxData(data);
caixa.setCxPlanoDeContas((PlanoDeContasBean) cbxPlano.getSelectedItem());
caixa.setCxTipoLancamento(String.valueOf(cbxTipo.getSelectedItem()));
caixa.setCxHistorico(txtHistorico.getText().toUpperCase());
caixa.setCxBanco((BancoBean) cbxBanco.getSelectedItem());
caixa.setCxValor(Double.parseDouble(txtValor.getText()));

control.salva();

} catch (ParseException ex) {
ex.printStackTrace();
}
}

On lines where I seto the chart of accounts and the bank makes a mistake ...
that can not convert String to PlanoDeContasBean or BancoBean ...
Could anyone help me? Thanks in advance!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.