//classe de domínio
@Entity
@Table(name = "CLIENTE")
@SequenceGenerator(name = "SEQ_ID_GEN_CLIENTE", sequenceName = "SEQ_ID_GEN_CLIENTE")
public class Cliente {
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_ID_GEN_CLIENTE")
private Long id;
@Column(name = "NOME")
@Length(min = 1, max = 255)
@NotEmpty
private String nome;
@Column(name = "CPF", length = 15)
@NotEmpty
private String cpf;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "cliente")
private List<CarroCliente> carros;
@ManyToOne
@JoinColumn(name = "ID_TIPO_CLIENTE_FK")
private TipoCliente tipoCliente;
@OneToMany(cascade = CascadeType.ALL,mappedBy="cliente")
private List<Lavagem> lavagens;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getCpf() {
return cpf;
}
public void setCpf(String cpf) {
this.cpf = cpf;
}
public List<CarroCliente> getCarros() {
return carros;
}
public void setCarros(List<CarroCliente> carros) {
this.carros = carros;
}
public TipoCliente getTipoCliente() {
return tipoCliente;
}
public void setTipoCliente(TipoCliente tipoCliente) {
this.tipoCliente = tipoCliente;
}
public List<Lavagem> getLavagens() {
return lavagens;
}
public void setLavagens(List<Lavagem> lavagens) {
this.lavagens = lavagens;
}
@Override
public boolean equals(Object obj){
if( (obj instanceof Cliente) && ( ((Cliente)obj).getId().equals(this.id)) ){
return true;
}else{
return false;
}
}
}
//imports
@Controller("clienteController")
public class ClienteController {
private Cliente cliente;
@Resource
private ClienteService clienteService;
@Resource
private TipoClienteService tpclienteservice;
private List<Cliente> clientes;
private List<SelectItem> tipoclientes = new ArrayList<SelectItem>();
public String deletar(){
clienteService.findCliente(this.cliente.getId()); //estou recuperando o objeto do banco antes de deletar mas mesmo assim não obtive sucesso
//Cliente cliente = this.clienteService.pesquisaClienteByCpf(this.cliente.getCpf());
clienteService.deleteCliente(this.cliente);
configCliente();
return "formDeletarCliente";
}
//outros metodos e setters e getters
}
estou usando JSF + Richfaces também
ja dei uma vasculhada sobre como remover mas não tive sucesso… e entendo mais ou menos o problema, mas como sou novato em tudo fica difícil saber como resolver.