我有两个Java类Product和ProductNote,并且我在Product中使用@Audit,但我不想在ProductNote上使用@Audit,但出现以下错误:
起因:org.hibernate.MappingException:com.test.test.domain.Product.productNotes与未经审计的实体com.test.test.domain.ProductNote!的审计关系!
代码:
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.envers.Audited;
import com.focusrunner.ezpill.Listeners.ProductListeners;
import io.swagger.annotations.ApiModel;
package com.focusrunner.ezpill.domain;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.envers.Audited;
import com.focusrunner.ezpill.Listeners.ProductListeners;
import io.swagger.annotations.ApiModel;
/**
* Stock entry
*
* @author anton
*/
@ApiModel(description = "Stock entry @author anton")
@Entity
@Table(name = "product")
@Audited
@EntityListeners(ProductListeners.class)
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Product implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotNull
@Size(max = 12)
@Column(name = "upc", length = 12, nullable = false)
private String upc;
@Size(min = 10, max = 10)
@Column(name = "ndc", length = 10)
private String ndc;
@Size(max = 255)
@Column(name = "name", length = 255)
private String name;
@Size(max = 255)
@Column(name = "strength", length = 255)
private String strength;
@Size(max = 255)
@Column(name = "form", length = 255)
private String form;
@Size(max = 255)
@Column(name = "jhi_size", length = 255)
private String size;
@Size(max = 255)
@Column(name = "lot", length = 255)
private String lot;
@Column(name = "expires")
private LocalDate expires;
@Column(name = "price", precision = 10, scale = 2)
private BigDecimal price;
@Size(max = 255)
@Column(name = "location", length = 255)
private String location;
@Column(name = "quantity")
private Long quantity;
@Size(max = 15)
@Column(name = "status", length = 15)
private String status;
@OneToMany(mappedBy = "product")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
private Set<ProductNote> productNotes = new HashSet<>();
// jhipster-needle-entity-add-field - JHipster will add fields here, do not remove
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getUpc() {
return upc;
}
public Product upc(String upc) {
this.upc = upc;
return this;
}
public void setUpc(String upc) {
this.upc = upc;
}
public String getNdc() {
return ndc;
}
public Product ndc(String ndc) {
this.ndc = ndc;
return this;
}
public void setNdc(String ndc) {
this.ndc = ndc;
}
public String getName() {
return name;
}
public Product name(String name) {
this.name = name;
return this;
}
public void setName(String name) {
this.name = name;
}
public String getStrength() {
return strength;
}
public Product strength(String strength) {
this.strength = strength;
return this;
}
public void setStrength(String strength) {
this.strength = strength;
}
public String getForm() {
return form;
}
public Product form(String form) {
this.form = form;
return this;
}
public void setForm(String form) {
this.form = form;
}
public String getSize() {
return size;
}
public Product size(String size) {
this.size = size;
return this;
}
public void setSize(String size) {
this.size = size;
}
public String getLot() {
return lot;
}
public Product lot(String lot) {
this.lot = lot;
return this;
}
public void setLot(String lot) {
this.lot = lot;
}
public LocalDate getExpires() {
return expires;
}
public Product expires(LocalDate expires) {
this.expires = expires;
return this;
}
public void setExpires(LocalDate expires) {
this.expires = expires;
}
public BigDecimal getPrice() {
return price;
}
public Product price(BigDecimal price) {
this.price = price;
return this;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
public String getLocation() {
return location;
}
public Product location(String location) {
this.location = location;
return this;
}
public void setLocation(String location) {
this.location = location;
}
public Long getQuantity() {
return quantity;
}
public Product quantity(Long quantity) {
this.quantity = quantity;
return this;
}
public void setQuantity(Long quantity) {
this.quantity = quantity;
}
public String getStatus() {
return status;
}
public Product status(String status) {
this.status = status;
return this;
}
public void setStatus(String status) {
this.status = status;
}
public Set<ProductNote> getProductNotes() {
return productNotes;
}
public Product productNotes(Set<ProductNote> productNotes) {
this.productNotes = productNotes;
return this;
}
public Product addProductNotes(ProductNote productNote) {
this.productNotes.add(productNote);
productNote.setProduct(this);
return this;
}
public Product removeProductNotes(ProductNote productNote) {
this.productNotes.remove(productNote);
productNote.setProduct(null);
return this;
}
public void setProductNotes(Set<ProductNote> productNotes) {
this.productNotes = productNotes;
}
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here, do not remove
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Product product = (Product) o;
if (product.getId() == null || getId() == null) {
return false;
}
return Objects.equals(getId(), product.getId());
}
@Override
public int hashCode() {
return Objects.hashCode(getId());
}
@Override
public String toString() {
return "Product{" +
"id=" + getId() +
", upc='" + getUpc() + "'" +
", ndc='" + getNdc() + "'" +
", name='" + getName() + "'" +
", strength='" + getStrength() + "'" +
", form='" + getForm() + "'" +
", size='" + getSize() + "'" +
", lot='" + getLot() + "'" +
", expires='" + getExpires() + "'" +
", price=" + getPrice() +
", location='" + getLocation() + "'" +
", quantity=" + getQuantity() +
", status='" + getStatus() + "'" +
"}";
}
}
@ApiModel(description = "ProductNotes for add deleted product note @author Sumit")
@Entity
@Table(name = "product_note")
@Audited
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class ProductNote implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Size(max = 255)
@Column(name = "note", length = 255)
private String note;
@Column(name = "jhi_timestamp")
private Instant timestamp;
@ManyToOne
@JsonIgnoreProperties("productNotes")
private Product product;
@ManyToOne
@JsonIgnoreProperties("productNotes")
private User user;
// jhipster-needle-entity-add-field - JHipster will add fields here, do not remove
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getNote() {
return note;
}
public ProductNote note(String note) {
this.note = note;
return this;
}
public void setNote(String note) {
this.note = note;
}
public Instant getTimestamp() {
return timestamp;
}
public ProductNote timestamp(Instant timestamp) {
this.timestamp = timestamp;
return this;
}
public void setTimestamp(Instant timestamp) {
this.timestamp = timestamp;
}
public Product getProduct() {
return product;
}
public ProductNote product(Product product) {
this.product = product;
return this;
}
public void setProduct(Product product) {
this.product = product;
}
public User getUser() {
return user;
}
public ProductNote user(User user) {
this.user = user;
return this;
}
public void setUser(User user) {
this.user = user;
}
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here, do not remove
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ProductNote productNote = (ProductNote) o;
if (productNote.getId() == null || getId() == null) {
return false;
}
return Objects.equals(getId(), productNote.getId());
}
@Override
public int hashCode() {
return Objects.hashCode(getId());
}
@Override
public String toString() {
return "ProductNote{" +
"id=" + getId() +
", note='" + getNote() + "'" +
", timestamp='" + getTimestamp() + "'" +
"}";
}
我不想为ProductNote生成历史记录和审核表。