我无法将OrderApprovalLevels
和QuoteApprovalLevels
与UserCustomer
一对一地映射到一起。我收到以下错误:
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: oqtPersistenceUnit] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915) [hibernate-entitymanager-3.6.10.Final.jar:3.6.10.Final]
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:74) [hibernate-entitymanager-3.6.10.Final.jar:3.6.10.Final]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:288) [spring-orm-3.2.4.RELEASE.jar:3.2.4.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310) [spring-orm-3.2.4.RELEASE.jar:3.2.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1541) [spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1479) [spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE]
... 33 more
Caused by: org.hibernate.HibernateException: Missing column: orderApprovalLevel in poqt01.oqt_user_ic01
源代码
/**
* Created with IntelliJ IDEA.
* User: vartiwari
* Date: 2/1/16
* Time: 5:22 PM
* To change this template use File | Settings | File Templates.
*/
@SuppressWarnings("PMD.UnusedPrivateField")
@Entity
@Table(name = "oqt_user_ic01")
@AssociationOverrides({
@AssociationOverride(name = "pk.user", joinColumns = @JoinColumn(name = "ftId")),
@AssociationOverride(name = "pk.customer", joinColumns = @JoinColumn(name = "ic01s"))
})
public class UserCustomer implements Serializable{
//'pk' refers to the composite key for oqt_user_ic01 with columns ftID for User and ic01 for Customer
private UserCustomerId pk;
private boolean ic01FromMSS;
@OneToOne(cascade = CascadeType.ALL)
@Column(name = "orderApprovalLevelId")
private OrderApprovalLevels orderApprovalLevel;
@OneToOne(cascade = CascadeType.ALL)
@Column(name = "quoteApprovalLevelId")
private QuoteApprovalLevels quoteApprovalLevel;
@EmbeddedId
public UserCustomerId getPk() {
if(pk == null){
pk = new UserCustomerId();
}
return pk;
}
public void setPk(UserCustomerId pk) {
this.pk = pk;
}
@Transient
public User getUser() {
return getPk().getUser();
}
public void setUser(User user){
getPk().setUser(user);
}
@Transient
public Customer getCustomer() {
return getPk().getCustomer();
}
public void setCustomer(Customer customer){
getPk().setCustomer(customer);
}
@Column(name = "ic01FromMSS",nullable = false)
public boolean isIc01FromMSS() {
return ic01FromMSS;
}
public void setIc01FromMSS(boolean ic01FromMSS) {
this.ic01FromMSS = ic01FromMSS;
}
public OrderApprovalLevels getOrderApprovalLevel() {
return orderApprovalLevel;
}
public void setOrderApprovalLevel(OrderApprovalLevels orderApprovalLevel) {
this.orderApprovalLevel = orderApprovalLevel;
}
public QuoteApprovalLevels getQuoteApprovalLevel() {
return quoteApprovalLevel;
}
public void setQuoteApprovalLevel(QuoteApprovalLevels quoteApprovalLevel) {
this.quoteApprovalLevel = quoteApprovalLevel;
}
}
@Entity
@Table(name="oqt_customer_quote_approval_levels")
@Getter
@Setter
@NoArgsConstructor
@SuppressWarnings({"PMD.UnusedPrivateField", "PMD.SingularField"})
public class QuoteApprovalLevels implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column
private Long id;
private Long approvalLevel;
private String approvalLabel;
}
答案 0 :(得分:0)
我认为您需要将@JoinColumn用于One-to-One关系
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "orderApprovalLevelId")
private OrderApprovalLevels orderApprovalLevel;