Last active
August 29, 2015 13:57
-
-
Save paulodiogo/9739556 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface Observavel{ | |
void adcionarObersavacao(Observacao observacao); | |
} | |
public class Observacao{ | |
@Column(name = "TX_OBSERVACAO") | |
private String observacao; | |
public Observacao(){} | |
public Observacao(String observacao){ | |
this.observacao = observacao; | |
} | |
//definindo | |
@Any(metaColumn = @Column(name = "TP_ENTIDADE")) | |
@AnyMetaDef(idType = "String", metaType = "long", metaValues = { @MetaValue(value = "ITEM", targetEntity = Item.class) }) | |
@JoinColumn(name = "ID_ENTIDADE") | |
private Observavel comentavel; | |
public void setObservavel(Observavel comentavel){ | |
this.comentavel = comentavel; | |
} | |
} | |
public class Item implements Observavel{ | |
@Id | |
@GeneratedValue(strategy = GenerationType.AUTO) | |
@Column(name = "ID_ITEM_LEVANT") | |
private Long id; | |
//invocando as observações passando o id da entidade | |
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) | |
@JoinColumn(name = "ID_ENTIDADE") | |
private List<Observacao> observacoes = new ArrayList<Observacao>(); | |
public void adcionarObersavacao(Observacao observacao){ | |
observacao.setObservavel(this); | |
this.observacoes.add(observacao); | |
} | |
} | |
public class DAO<Item>{ | |
public Item save(Item item, String observacao){ | |
//isso deve estar em uma factory | |
Observacao observacao = new Observacao(observacao); | |
item.adcionarObersavacao(observacao); | |
this.save(item); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment