-->
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.  [ 2 posts ] 
Author Message
 Post subject: Entity does not get persisted but sequence gets incremented
PostPosted: Thu Jan 20, 2011 2:42 pm 
Newbie

Joined: Thu Jan 20, 2011 2:31 pm
Posts: 4
Hello!

I have a very strange problem (i should mention that i am new in the hibernate world so i consider a lot of things strange yet), the thing is that i have an entity which when persisted via an entityManager.merge method does not get saved, however if i manually get the next value of the id sequence (i am using postgresql) i see that such sequence has been incremented...

does this sound familiar to anyone?

this is the class

@Entity
@Table(name = "preferencias", schema = "general", uniqueConstraints = @UniqueConstraint(columnNames = {"deleted", "descripcion" }))
public class Preferencia extends AbstractPersistentDTO {

private long id;
private boolean deleted;
private String descripcion;
private double valor;
private Set<PreferenciaUsuario> preferenciaUsuarios;

/**
* Constructor sin parametros necesario para cumplir con la especificacion de bean
*/
public Preferencia() {}

/**
* Inicializa la preferencia con los parametros recibidos
* @param id de la preferencia
* @param deleted indica si esta borrado o no
* @param descripcion de la preferencia
* @param valor de la preferencia
*/
public Preferencia(long id, boolean deleted, String descripcion, double valor) {
this.id = id;
this.deleted = deleted;
this.descripcion = descripcion;
this.valor = valor;
}

/**
* Inicializa la preferencia con los parametros recibidos
* @param id de la preferencia
* @param deleted indica si esta borrado o no
* @param descripcion de la preferencia
* @param valor de la preferencia
* @param conjunto de asociaciones que vinculan esta preferencia con algun usuario
*/
public Preferencia(long id, boolean deleted, String descripcion, double valor, Set<PreferenciaUsuario> preferenciaUsuarios) {
this.id = id;
this.deleted = deleted;
this.descripcion = descripcion;
this.valor = valor;
this.preferenciaUsuarios = preferenciaUsuarios;
}

/**
* Devuelve el id de la preferencia
* @return id de la preferencia
*/
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "general.preferencias_seq")
@SequenceGenerator(name = "general.preferencias_seq", sequenceName = "general.preferencias_seq", allocationSize=1)
@Column(name = "id", unique = true, nullable = false)
public long getId() {
return this.id;
}

/**
* Establece el id de la preferencia
* @param id de la preferencia
*/
public void setId(long id) {
this.id = id;
}

/**
* Devuelve el valor que indica si esta borrado o no
* @return el valor que indica si esta borrado o no
*/
@Column(name = "deleted", nullable = false)
public boolean isDeleted() {
return this.deleted;
}

/**
* Establece el valor que indica si esta borrado o no
* @param indica si esta borrado o no
*/
public void setDeleted(boolean deleted) {
this.deleted = deleted;
}

/**
* Devuelve la descripcion de la preferencia
* @return descripcion de la preferencia
*/
@Column(name = "descripcion", nullable = false)
public String getDescripcion() {
return this.descripcion;
}

/**
* Establece la descripcion de la preferencia
* @param descripcion de la preferencia
*/
public void setDescripcion(String descripcion) {
this.descripcion = descripcion;
}

/**
* Devuelve el valor de la preferencia
* @return valor de la preferencia
*/
@Column(name = "valor", nullable = false, precision = 17, scale = 17)
public double getValor() {
return this.valor;
}

/**
* Establece el valor de la preferencia
* @param valor de la preferencia
*/
public void setValor(double valor) {
this.valor = valor;
}

/**
* Devuelve el conjunto de asociaciones que vinculan a esta preferencia con algun usuario
* @return conjunto de asociaciones que vinculan a esta preferencia con algun usuario
*/
@OneToMany(fetch = FetchType.LAZY, mappedBy = "preferencia")
public Set<PreferenciaUsuario> getPreferenciaUsuarios() {
return this.preferenciaUsuarios;
}

/**
* Establece el conjunto de asociaciones que vinculan a esta preferencia con algun usuario
* @param conjunto de asociaciones que vinculan a esta preferencia con algun usuario
*/
public void setPreferenciaUsuarios(Set<PreferenciaUsuario> preferenciaUsuarios) {
this.preferenciaUsuarios = preferenciaUsuarios;
}
}

I am using Gilead to combine GWT and Hibernate in order to connect with a PostgreSQL database...

any pointers will be greatly appreciated

Thanks in advance!


Top
 Profile  
 
 Post subject: Re: Entity does not get persisted but sequence gets incremented
PostPosted: Thu Jan 20, 2011 3:27 pm 
Newbie

Joined: Thu Jan 20, 2011 2:31 pm
Posts: 4
¡Solved!

In order to describe the solution i should mention that i use DAO interfaces with JPA implementations to manipulate my persistent entities. That being said, the problem was the transaction annotation on the save method:

how it was before:

@Transactional(propagation=Propagation.SUPPORTS)
public Area save(Area area){
return entityManager.merge(area);
}

how it is now:

@Transactional(propagation=Propagation.REQUIRED)
public Area save(Area area){
return entityManager.merge(area);
}

However, being as i am, a total newbie, i would be lying if i said i understood what prevented the save of the entity but nevertheless permited the increment of the sequence so i welcome any insight or comment anyone has to offer

Thanks in advance!

Cheers!

Rafael


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

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.