I have a Uni directional one -to-many relationship defined in a class and trying to audit the collection and the join key column in the audit table is inserting with null values, Could anyone help me how to do this?
The example is given below. A Search class which contains a set of SearchParameters. Both of these classes are mapped to tables search and search_param. the class stucture and table structure is given below.
@Entity
@BatchSize(size = 1000)
@Table(schema = "Search")
@Audited
@AuditTable(schema = "Customer" value = "Search_audit")
@Cache(region = "Search", usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Search{
private Long id;
private String description;
private String isSticky;
private Set<SearchParameter> searchParams;
/**
@return the deletedFlag
*/
public Search() {
}
public void setDescription(String description) {
this.description = description;
}
@Column(name = "DESCRIPTION")
public String getDescription() {
return description;
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
return id;
}
@Column(name = "IS_STICKY")
public String getIsSticky() {
return isSticky;
}
public void setId(Long id) {
this.id = id;
}
public void setIsSticky(String isSticky) {
this.isSticky = isSticky;
}
@MapKeyJoinColumn(name="SEARCH_ID")
@Fetch(FetchMode.SUBSELECT)
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "SEARCH_ID")
@Cache(region = "Search.searchParams", usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public Set<SearchParameter> getSearchParams() {
return searchParams;
}
public void setSearchParams(Set<SearchParameter> parameters) {
this.searchParams = parameters;
}
}
@Entity
@BatchSize(size = 1000)
@Table(name = "Search_Param")
@Audited
@AuditTable(schema = "Customer" value = "Search_param_audit")
@Cache(region = "SearchParameter", usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class SearchParameter extends AbstractDomainObject {
private Long id;
private String name;
private Set<SearchParameterValue> searchValues;
/*
@return the id
*/
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
return id;
}
/**
@param id
* the id to set
*/
public void setId(Long id) {
this.id = id;
}
/**
@return the name
*/
@Column(name = "NAME")
public String getName() {
return name;
}
/**
@param name
* the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
@param searchValues
* the searchValues to set
*/
public void setSearchValues(Set<SearchParameterValue> searchValues) {
this.searchValues = searchValues;
}
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
@Fetch(FetchMode.SUBSELECT)
@OneToMany(orphanRemoval = true, fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "PARAMETER_ID")
@Cache(region = "SearchParameter.searchValues", usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public Set<SearchParameterValue> getSearchValues() {
return searchValues;
}
}
The search_id in the search_param_audit table always stored as null while auditing the data.
What I should do to fix this?
Win
Any thoughts regarding my last comment? Can I close the ticket?
This is just a thought that why the envers cannot audit the data for one-to- many relationship without an intersection table? the hibernate is managed to persist the data to the underlying tables without a ternary table then why the envers is forcing for a intersection table?
Thank you guys, Now I have a new intersection table and the AuditReader is pulling all the revisions as well.
Based on comments, closing.