| Hi, I have a problem using Hibernate @Where annnotation with Soft Delete. I have a entity class with soft delete and @where clause enabled.
@Entity
@Table(name = "Cat_Turnos")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "CatTurnos.findAll", query = "SELECT c FROM CatTurnos c ORDER BY c.nombre")
....
)})
@SQLDelete(sql="UPDATE Cat_Turnos SET deleted = '1', FechaDeleted = GETDATE() WHERE idTipoTurno = ?")
@Where(clause="deleted <> '1'")
public class CatTurnos implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = javax.persistence.GenerationType.IDENTITY)
@Column(name = "idTipoTurno")
private Integer idTipoTurno;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 2)
@Column(name = "turno")
private String turno;
....
The other entity has a reference to the previous one, it has a @ManyToOne Relationship like this
@Entity
@Audited
@Table(name = "Cua_Turnos")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "Turnos.findAll", query = "SELECT t FROM Turnos t")
....
})
public class Turnos implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = javax.persistence.GenerationType.IDENTITY)
@Column(name = "idTurno")
private Integer idTurno;
@Basic(optional = false)
@NotNull
@Column(name = "fecha")
@Temporal(TemporalType.TIMESTAMP)
private Date fecha;
@Size(max = 5)
@Column(name = "inicio")
private String inicio;
@Size(max = 5)
@Column(name = "fin")
private String fin;
@JoinColumn(name = "idTipoTurno", referencedColumnName = "idTipoTurno")
@ManyToOne
@Audited(targetAuditMode = NOT_AUDITED)
private CatTurnos idTipoTurno;
....
I have a problem when getting an entity "Turnos" which foreign "CatTurnos" has been soft deleted. I get an error where the id of "CatTurnos" is not found and i can't get the Result Set when querying all entities of type "Turnos". I think the @Where clause is filtering the Objects "CatTurnos" even when they are referenced by another object (Only in the case the relationship is @ManyToOne) ¿Is there any workaround to solve it? I dont want to get entities of type "CatTurnos" when directly queried, but i want them when its being queried by a relationship of another entity (In this case the entity "Turnos" with @ManyToOne relationship) |