1
I’m setting up audit on a project with JSF
+ Hibernate
+ Demoiselle
.
Item class:
@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;
In the Persistenceauditor:
@PostPersist
public void postPersist(Object object) {
... consome auditoria
And to record:
@Transactional
public String insert() {
this.itemBC.insert(this.getBean());
return getPreviousView();
}
Itembc
@BusinessController
public class ItemBC extends DelegateCrudExt<Item, Long, ItemDAO> {
The audit is persisted but with the objects with id null as if taking the object before being "commited" and I would like the object already updated. Perhaps because of the @Transactional.
Output from the object:
Item{"id":69,"params":[{"id":null,"valor":10.0"}]}
ItemParam{"id":3,"valor":10.0}
Where it should be something like:
Item{"id":69,"params":[{"id": 3,"valor":10.0"}]}
ItemParam{"id":3, "item":69, "valor":10.0}
Any ideas on how to fix this?
Is there any way to put the code for this.itemBC.Insert(this.getBean()) function? A full Item class would also help a lot!
– Sérgio Mucciaccia
Itembc Insert uses the direct Insert of Demoiselle but I posted it and also the item class and the daughter class (Itemparam)
– Eduardo Debom