Boa tarde amigos, so estou conseguindo executar o insert no banco, usando hibernate, o update simplismente não executa…seguem as classes:
[code] public Cliente update(Cliente cliente) {
System.out.println(“atualizando em 3…2…1”);
Cliente byId = this.getCliente(cliente.getId());
byId.setNome(cliente.getNome());
byId.setCpf(cliente.getCpf());
byId.setEmail(cliente.getEmail());
getSession().save(cliente);
return byId;
}[/code]
@PUT
@Path("{id}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public void update(Cliente cliente) {
System.out.println("atualizando update");
clienteDAO.update(cliente);
}
o que sera que estou fazendo errado? configurei para apresentar o sq no console, realmente não executa update.
Estou fazendo uso de rest.
Está dando algum erro? Se sim, qual?
se deixo com o “save” ele executa
porem se altero para “saveOrupdate”
select cliente0_.id as id2_0_, cliente0_.cpf as
…
somente executa o insert ja tentei usar apenas update, saverOrupdate…
Deixe mais claro seu erro, sua duvida, seu código.
Do jeito que vc está dizendo, dá a entender que o saveOrUpdate do hibernate não funciona, o que não é verdade.
EDIT:
Segundo a documentação do Hibernate
[quote]saveOrUpdate() does the following:
if the object is already persistent in this session, do nothing
if another object associated with the session has the same identifier, throw an exception
if the object has no identifier property, save() it
if the object’s identifier has the value assigned to a newly instantiated object, save() it
if the object is versioned by a or , and the version property value is the same value assigned to a newly instantiated object, save() it
otherwise update() the object[/quote]
minha duvida é, o metodo save insere no banco normalmente, porem o metodo saveOrupdate ou somente update, executa um “select”.
quero executar o update, onde posso estar errando?