我在调用refresh方法时遇到错误。我有下表:Ontology,Publication和ontology_by_publication。
这是本体的pk:ontology_id |自动递增 这是出版物的pk:publication_id |自动递增 这是ontology_by_publication pk:publication_publication_id,ontology_ontology_id,ontology_by_publication_id
列ontology_by_publication_id具有自动增量设置。
我的OntologyByPublication看起来像这样:
@Entity
@Table(name = "ontology_by_publication")
public class OntologyByPublication implements Serializable {
/**
*
*/
private static final long serialVersionUID = -7427863218422284148L;
@EmbeddedId
private OntologyByPublicationId ontologyByPublicationId;
@Column(name = "description")
private String description;
@Column(name = "current_price")
private Double currentPrice;
@MapsId(value = "ontologyId")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ontology_ontology_id")
private Ontology ontology;
@MapsId(value = "publicationId")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "publication_publication_id")
private Publication publication;
getters - setters
这是@Embeddable类:
@Embeddable
public class OntologyByPublicationId implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
@Column(name = "ontology_by_publication_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long ontologyByPubId;
@Column(name = "publication_publication_id")
private Long publicationId;
@Column(name = "ontology_ontology_id")
private Integer ontologyId;
我调用下面的方法来持久化OntologyByPublication对象:
public OntologyByPublication saveOntologyByPublicationRefresh(
OntologyByPublication ontologyByPublication) {
try
{
em.persist(ontologyByPublication);
em.flush();
em.refresh(ontologyByPublication);
return ontologyByPublication;
}
catch (Exception ex)
{
return null;
}
}
当执行包含em.refresh的行时,抛出此异常:
javax.persistence.EntityNotFoundException: No row with the given identifier exists: [org.springtest.mavenspringapp.domain.OntologyByPublication#org.springtest.mavenspringapp.domain.OntologyByPublicationId@73ba7b18]
我不知道我做错了什么。请帮帮我。