0
我無法一一映射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;
}
是的..我們有柱orderApprovalLevelId這映射爲外鍵到表oqt_customer_approval級別。 – simba
我已經添加了上面的代碼。 – simba
查看堆棧跟蹤我不確定它是否是錯誤的原因,但是您在字段(字段訪問)以及getter(屬性訪問)上使用映射註釋,在這種情況下行爲未定義。所以你必須首先糾正,如果它仍然沒有工作,至少你已經排除了一個可能的原因。對於定義混合訪問模式看看我的答案[這個問題](http://stackoverflow.com/questions/38728671/column-annotation-does-not-work/38730149#38730149)。 – ujulu