I'm setting up auditing on a project with JSF
+ Hibernate
+ Demoiselle
.
Class Item:
@Entity
@Cacheable(true)
@Table(name = "itens")
@EntityListeners(value = PersistenceAuditor.class)
@XmlRootElement
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class Item {
private static final long serialVersionUID = 1L;
@Id
GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Long id;
@LazyCollection(LazyCollectionOption.FALSE)
@OneToMany(mappedBy = "item", orphanRemoval = true, cascade = {CascadeType.PERSIST, CascadeType.REMOVE})
@JsonManagedReference(value="itemParam")
private List<ItemParam> params;
ItemParam Class:
@Entity
@Cacheable(true)
@Table(name = "item_params")
@EntityListeners(value = PersistenceAuditor.class)
@XmlRootElement
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class ItemParam {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Long id;
@NotNull
@ManyToOne
@JoinColumn(name = "item_id", referencedColumnName = "id", nullable = false)
@JsonBackReference(value="itemParam")
private Item item;
No PersistenceAuditor:
@PostPersist
public void postPersist(Object object) {
... consome auditoria
And to save:
@Transactional
public String insert() {
this.itemBC.insert(this.getBean());
return getPreviousView();
}
ItemBC
@BusinessController
public class ItemBC extends DelegateCrudExt<Item, Long, ItemDAO> {
Audit is persistent however with objects with id null as if it took the object before it was "comitative" and I would like the object already updated. Maybe because of the @Transactional.
Object output:
Item{"id":69,"params":[{"id":null,"valor":10.0"}]}
ItemParam{"id":3,"valor":10.0}
Where should be something like:
Item{"id":69,"params":[{"id": 3,"valor":10.0"}]}
ItemParam{"id":3, "item":69, "valor":10.0}
Any ideas to solve this?