Olá.
Tô com um probleminha na hora de cadastrar.
Veja as classes que estou manuseando:/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package br.com.Dominio;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import org.hibernate.annotations.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Lob;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.Cascade;
/**
*
* @author Jackeline
*/
@Entity
@Inheritance(strategy= InheritanceType.JOINED)
@Table(name = "Usuario", catalog = "dbSistemaBibliotecario", schema = "dbo")
@NamedQueries({
@NamedQuery(name = "Usuario.findAll", query = "SELECT u FROM Usuario u"),
@NamedQuery(name = "Usuario.findByCodUsuario", query = "SELECT u FROM Usuario u WHERE u.codUsuario = :codUsuario"),
@NamedQuery(name = "Usuario.findByNoUsuario", query = "SELECT u FROM Usuario u WHERE u.noUsuario = :noUsuario"),
@NamedQuery(name = "Usuario.findByDaNascimento", query = "SELECT u FROM Usuario u WHERE u.daNascimento = :daNascimento"),
@NamedQuery(name = "Usuario.findByTxSexo", query = "SELECT u FROM Usuario u WHERE u.txSexo = :txSexo"),
@NamedQuery(name = "Usuario.findByNuCPF", query = "SELECT u FROM Usuario u WHERE u.nuCPF = :nuCPF"),
@NamedQuery(name = "Usuario.findByNuRG", query = "SELECT u FROM Usuario u WHERE u.nuRG = :nuRG"),
@NamedQuery(name = "Usuario.findByTxLogradouro", query = "SELECT u FROM Usuario u WHERE u.txLogradouro = :txLogradouro"),
@NamedQuery(name = "Usuario.findByNuCasa", query = "SELECT u FROM Usuario u WHERE u.nuCasa = :nuCasa"),
@NamedQuery(name = "Usuario.findByTxBairro", query = "SELECT u FROM Usuario u WHERE u.txBairro = :txBairro"),
@NamedQuery(name = "Usuario.findByTxCidade", query = "SELECT u FROM Usuario u WHERE u.txCidade = :txCidade"),
@NamedQuery(name = "Usuario.findByNuCep", query = "SELECT u FROM Usuario u WHERE u.nuCep = :nuCep"),
@NamedQuery(name = "Usuario.findByTxUF", query = "SELECT u FROM Usuario u WHERE u.txUF = :txUF"),
@NamedQuery(name = "Usuario.findByNuTelefone", query = "SELECT u FROM Usuario u WHERE u.nuTelefone = :nuTelefone"),
@NamedQuery(name = "Usuario.findByNuCelular", query = "SELECT u FROM Usuario u WHERE u.nuCelular = :nuCelular"),
@NamedQuery(name = "Usuario.findByTxEmail", query = "SELECT u FROM Usuario u WHERE u.txEmail = :txEmail"),
@NamedQuery(name = "Usuario.findByTxObservacao", query = "SELECT u FROM Usuario u WHERE u.txObservacao = :txObservacao"),
@NamedQuery(name = "Usuario.findByDaCadastro", query = "SELECT u FROM Usuario u WHERE u.daCadastro = :daCadastro"),
@NamedQuery(name = "Usuario.findByNuSenhaConfirmacao", query = "SELECT u FROM Usuario u WHERE u.nuSenhaConfirmacao = :nuSenhaConfirmacao")})
public class Usuario implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "CodUsuario", nullable = false)
private Integer codUsuario;
@Basic(optional = false)
@Column(name = "NoUsuario", nullable = false, length = 100)
private String noUsuario;
@Basic(optional = false)
@Column(name = "DaNascimento", nullable = false)
@Temporal(TemporalType.DATE)
private Date daNascimento;
@Basic(optional = false)
@Column(name = "TxSexo", nullable = false)
private char txSexo;
@Column(name = "NuCPF", length = 15)
private String nuCPF;
@Basic(optional = false)
@Column(name = "NuRG", nullable = false, length = 12)
private String nuRG;
@Basic(optional = false)
@Column(name = "TxLogradouro", nullable = false, length = 100)
private String txLogradouro;
@Basic(optional = false)
@Column(name = "NuCasa", nullable = false, length = 10)
private String nuCasa;
@Basic(optional = false)
@Column(name = "TxBairro", nullable = false, length = 50)
private String txBairro;
@Basic(optional = false)
@Column(name = "TxCidade", nullable = false, length = 50)
private String txCidade;
@Basic(optional = false)
@Column(name = "NuCep", nullable = false, length = 8)
private String nuCep;
@Basic(optional = false)
@Column(name = "TxUF", nullable = false, length = 2)
private String txUF;
@Column(name = "NuTelefone", length = 13)
private String nuTelefone;
@Basic(optional = false)
@Column(name = "NuCelular", nullable = false, length = 13)
private String nuCelular;
@Column(name = "TxEmail", length = 100)
private String txEmail;
@Column(name = "TxObservacao", length = 200)
private String txObservacao;
@Basic(optional = false)
@Column(name = "DaCadastro", nullable = false)
@Temporal(TemporalType.TIMESTAMP)
private Date daCadastro;
@Basic(optional = false)
@Column(name = "NuSenhaConfirmacao", nullable = false, length = 6)
private String nuSenhaConfirmacao;
@Lob
@Column(name = "Foto")
private byte[] foto;
/**a anotação @OneToMany, que indica que se trata de um relacionamento um para muitos,
* e também pode-se observar os atributos cascade que indica como as alterações serão feitas
* e mappedBy que apresenta com qual propriedade se relaciona.
*/
@OneToMany(mappedBy = "codUsuario", fetch= FetchType.LAZY)
@Cascade(CascadeType.SAVE_UPDATE)
private Collection<Reserva> reserva = new ArrayList<Reserva>();
@OneToMany(mappedBy = "codUsuario", fetch= FetchType.LAZY)
@Cascade(CascadeType.SAVE_UPDATE)
private Collection<Emprestimo> emprestimo = new ArrayList<Emprestimo>();
public Usuario() {
}
public Usuario(Integer codUsuario) {
this.codUsuario = codUsuario;
}
/**Os atributos que não possuem o construtor this e o annotation de parâmentro é porque podem ser nulos.
* @param codUsuario
* @param noUsuario
* @param daNascimento
* @param txSexo
* @param nuRG
* @param txBairro
* @param txLogradouro
* @param txCidade
* @param nuCasa
* @param nuSenhaConfirmacao
* @param nuCep
* @param txUF
* @param daCadastro
* @param nuCelular
*/
public Usuario(Integer codUsuario, String noUsuario, Date daNascimento, char txSexo, String nuRG, String txLogradouro, String nuCasa, String txBairro, String txCidade, String nuCep, String txUF, String nuCelular, Date daCadastro, String nuSenhaConfirmacao) {
this.codUsuario = codUsuario;
this.noUsuario = noUsuario;
this.daNascimento = daNascimento;
this.txSexo = txSexo;
this.nuRG = nuRG;
this.txLogradouro = txLogradouro;
this.nuCasa = nuCasa;
this.txBairro = txBairro;
this.txCidade = txCidade;
this.nuCep = nuCep;
this.txUF = txUF;
this.nuCelular = nuCelular;
this.daCadastro = daCadastro;
this.nuSenhaConfirmacao = nuSenhaConfirmacao;
}
public Integer getCodUsuario() {
return codUsuario;
}
public void setCodUsuario(Integer codUsuario) {
this.codUsuario = codUsuario;
}
public String getNoUsuario() {
return noUsuario;
}
public void setNoUsuario(String noUsuario) {
this.noUsuario = noUsuario;
}
public Date getDaNascimento() {
return daNascimento;
}
public void setDaNascimento(Date daNascimento) {
this.daNascimento = daNascimento;
}
public char getTxSexo() {
return txSexo;
}
public void setTxSexo(char txSexo) {
this.txSexo = txSexo;
}
public String getNuCPF() {
return nuCPF;
}
public void setNuCPF(String nuCPF) {
this.nuCPF = nuCPF;
}
public String getNuRG() {
return nuRG;
}
public void setNuRG(String nuRG) {
this.nuRG = nuRG;
}
public String getTxLogradouro() {
return txLogradouro;
}
public void setTxLogradouro(String txLogradouro) {
this.txLogradouro = txLogradouro;
}
public String getNuCasa() {
return nuCasa;
}
public void setNuCasa(String nuCasa) {
this.nuCasa = nuCasa;
}
public String getTxBairro() {
return txBairro;
}
public void setTxBairro(String txBairro) {
this.txBairro = txBairro;
}
public String getTxCidade() {
return txCidade;
}
public void setTxCidade(String txCidade) {
this.txCidade = txCidade;
}
public String getNuCep() {
return nuCep;
}
public void setNuCep(String nuCep) {
this.nuCep = nuCep;
}
public String getTxUF() {
return txUF;
}
public void setTxUF(String txUF) {
this.txUF = txUF;
}
public String getNuTelefone() {
return nuTelefone;
}
public void setNuTelefone(String nuTelefone) {
this.nuTelefone = nuTelefone;
}
public String getNuCelular() {
return nuCelular;
}
public void setNuCelular(String nuCelular) {
this.nuCelular = nuCelular;
}
public String getTxEmail() {
return txEmail;
}
public void setTxEmail(String txEmail) {
this.txEmail = txEmail;
}
public String getTxObservacao() {
return txObservacao;
}
public void setTxObservacao(String txObservacao) {
this.txObservacao = txObservacao;
}
public Date getDaCadastro() {
return daCadastro;
}
public void setDaCadastro(Date daCadastro) {
this.daCadastro = daCadastro;
}
public String getNuSenhaConfirmacao() {
return nuSenhaConfirmacao;
}
public void setNuSenhaConfirmacao(String nuSenhaConfirmacao) {
this.nuSenhaConfirmacao = nuSenhaConfirmacao;
}
public byte[] getFoto() {
return foto;
}
public void setFoto(byte[] foto) {
this.foto = foto;
}
public Collection<Emprestimo> getEmprestimo() {
return emprestimo;
}
public void setEmprestimo(Collection<Emprestimo> emprestimo) {
this.emprestimo = emprestimo;
}
public Collection<Reserva> getReserva() {
return reserva;
}
public void setReserva(Collection<Reserva> reserva) {
this.reserva = reserva;
}
@Override
public int hashCode() {
int hash = 0;
hash += (codUsuario != null ? codUsuario.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 Usuario)) {
return false;
}
Usuario other = (Usuario) object;
if ((this.codUsuario == null && other.codUsuario != null) || (this.codUsuario != null && !this.codUsuario.equals(other.codUsuario))) {
return false;
}
return true;
}
@Override
public String toString() {
return "br.com.Dominio.Usuario[ codUsuario=" + codUsuario + " ]";
}
}
String sexo = "";
if (cmdSexoFemininoAluno.isSelected())
sexo = "F";
else
sexo = "M";
aluno.setTxSexo(sexo);
Só que diz que no set do sexo:
[color=blue]
required: char
found: java.lang.String
reason: actual argument java.lang.String cannot be converted to char by method invocation conversion[/color]
Tem como eu converter para string? Como faço isso?
