2

Getting below error when trying to deploy application on Jboss:

Services which failed to start: service jboss.undertow.deployment.default-server.default-host./naturallatex-rest: java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Unable to find column with logical name: customerCollection in org.hibernate.mapping.Table(natural_latex.billing_address) and its related supertables and secondary tables

Customer.java:

package naturallatex.entity; import java.io.Serializable; import java.util.Date; import javax.persistence.Basic; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.validation.constraints.Size; import javax.xml.bind.annotation.XmlRootElement; /** * * @author sam */ @Entity @Table(name = "customer", catalog = "natural_latex", schema = "") @XmlRootElement public class Customer implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "cust_id") @Basic(optional = false) private Integer custId; @Size(max = 60) @Column(name = "first_name") private String firstName; @Size(max = 60) @Column(name = "last_name") private String lastName; @Size(max = 256) private String password; @Size(max = 125) @Column(name = "email_address") private String emailAddress; @Size(max = 60) private String phone; @Size(max = 56) private String fax; private Boolean status; @Column(name = "reg_date") @Temporal(TemporalType.DATE) private Date regDate; @Column(name = "cancel_date") @Temporal(TemporalType.DATE) private Date cancelDate; @JoinColumn(name = "billing_address_id", referencedColumnName = "customerCollection") @ManyToOne(optional = false) private BillingAddress billingAddressId; @JoinColumn(name = "shipping_address_id", referencedColumnName = "customerCollection") @ManyToOne(optional = false) private ShippingAddress shippingAddressId; public Customer() { } public Customer(Integer cust_id) { this.custId = cust_id; } public Integer getId() { return custId; } public void setId(Integer cust_id) { this.custId = cust_id; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getEmailAddress() { return emailAddress; } public void setEmailAddress(String emailAddress) { this.emailAddress = emailAddress; } public String getPhone() { return phone; } public void setPhone(String phone) { this.phone = phone; } public String getFax() { return fax; } public void setFax(String fax) { this.fax = fax; } public Boolean getStatus() { return status; } public void setStatus(Boolean status) { this.status = status; } public Date getRegDate() { return regDate; } public void setRegDate(Date regDate) { this.regDate = regDate; } public Date getCancelDate() { return cancelDate; } public void setCancelDate(Date cancelDate) { this.cancelDate = cancelDate; } public BillingAddress getBillingAddressId() { return billingAddressId; } public void setBillingAddressId(BillingAddress billingAddressId) { this.billingAddressId = billingAddressId; } public ShippingAddress getShippingAddressId() { return shippingAddressId; } public void setShippingAddressId(ShippingAddress shippingAddressId) { this.shippingAddressId = shippingAddressId; } @Override public int hashCode() { int hash = 0; hash += (custId != null ? custId.hashCode() : 0); return hash; } @Override public boolean equals(Object object) { // TODO: Warning - this method won't work in the case the id fields are not set if (!(object instanceof Customer)) { return false; } Customer other = (Customer) object; if ( (this.custId == null && other.custId != null) || (this.custId != null && !this.custId.equals(other.custId)) ) { return false; } return true; } @Override public String toString() { return "naturallatex.Customer[ id=" + custId + " ]"; } } 

BillingAddress.java :

@OneToMany(cascade = CascadeType.ALL, mappedBy = "billingAddressId") private Collection<Customer> customerCollection; 

What should be the value for referencedColumnName ?

getting below exception now.

Services which failed to start: service >jboss.undertow.deployment.default-server.default-host./naturallatex-rest: >java.lang.RuntimeException: >org.springframework.beans.factory.BeanCreationException: Error creating bean >with name 'entityManagerFactory' defined in class path resource >>

[org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]>: Invocation of init method failed; nested exception is ?>org.hibernate.MappingException: Unable to find column with logical name: id in >org.hibernate.mapping.Table(natural_latex.billing_address) and its related >supertables and secondary tables

1 Answer 1

1

referencedColumnName defines the name of the column in the other entity which would be referred as your foreign key.

In your table for BillingAddress entity, hibernate is expecting to have one column with the name customerCollection where as in BillingAddress entity it seems you do not have any column named customerCollection what you have is the object to specify bidirectional relationship with the Customer Entity.

Therefore, in your referencedColumnName mention the name of database column in BillingAddress entity which would serve as foreign key with Customer entity.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot for the help

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.