Skip to content

Instantly share code, notes, and snippets.

@fabriciofx
Forked from rponte/Bem.java
Created April 6, 2014 05:35
Show Gist options
  • Save fabriciofx/10001880 to your computer and use it in GitHub Desktop.
Save fabriciofx/10001880 to your computer and use it in GitHub Desktop.
@Entity
public class Bem implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne
@JoinColumn(nullable = false)
private Lotacao lotacao;
@Transient
private boolean estaAtreladoAMovimentacao;
/**
* Default constructor
* /
public Bem() {}
public Bem(Bem bem, boolean estaAtreladoAMovimentacao) {
this.id = bem.id;
this.lotacao = bem.lotacao;
this.estaAtreladoAMovimentacao = estaAtreladoAMovimentacao;
}
public Bem(Bem bem, Long movId) {
this.id = bem.id;
this.lotacao = bem.lotacao;
this.estaAtreladoAMovimentacao = movId != null;
}
}
select new Bem(bem, case when mov.id is not null then true else false end)
from Movimentacao mov
left join mov.bem as bem
with bem.lotacao = :lotacao
where mov.id = 69
select new Bem(bem, mov.id)
from Movimentacao mov
left join mov.bem as bem
with bem.lotacao = :lotacao
where mov.id = 69
@Entity
public class Movimentacao implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne
@JoinColumn(nullable = false)
private Bem bem;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment