Hi,
I am running into a strange issue. I am using intelliJ IDEA to automatically create annotated classes from a simple (personal tutorial) database schema consisting of three tables: address, state and country. The three annotated classes are generated accordingly (and according to the api), but when I try to create a session factory bean (with spring) I get the following runtime error:
org.hibernate.AnnotationException: Cannot find the expected secondary table: no address available for ...'
it appears that it is coming from the 'table' attribute in @JoinColumn, but from what I can tell, there is nothing wrong with this, and I presume that the IDE would generate the annotations properly? Anyone have any ideas (do I need to run some class modifying tool):
@Entity public class Address { private long itsAddressId;
@Column (name = "address_id", nullable = false, insertable = false, updatable = false, length = 19, precision = 0) @Id public long getAddressId() { return itsAddressId; }
public void setAddressId(long inAddressId) { itsAddressId = inAddressId; }
private String itsName;
@Column (name = "name", nullable = true, insertable = true, updatable = true, length = 128, precision = 0) @Basic public String getName() { return itsName; }
public void setName(String inName) { itsName = inName; }
private String itsAddress1;
@Column (name = "address1", nullable = false, insertable = true, updatable = true, length = 128, precision = 0) @Basic public String getAddress1() { return itsAddress1; }
public void setAddress1(String inAddress1) { itsAddress1 = inAddress1; }
private String itsAddress2;
@Column (name = "address2", nullable = true, insertable = true, updatable = true, length = 128, precision = 0) @Basic public String getAddress2() { return itsAddress2; }
public void setAddress2(String inAddress2) { itsAddress2 = inAddress2; }
private String itsAddress3;
@Column (name = "address3", nullable = true, insertable = true, updatable = true, length = 128, precision = 0) @Basic public String getAddress3() { return itsAddress3; }
public void setAddress3(String inAddress3) { itsAddress3 = inAddress3; }
private String itsCity;
@Column (name = "city", nullable = false, insertable = true, updatable = true, length = 128, precision = 0) @Basic public String getCity() { return itsCity; }
public void setCity(String inCity) { itsCity = inCity; }
private String itsZip;
@Column (name = "zip", nullable = false, insertable = true, updatable = true, length = 16, precision = 0) @Basic public String getZip() { return itsZip; }
public void setZip(String inZip) { itsZip = inZip; }
private String itsPhone1;
@Column (name = "phone1", nullable = true, insertable = true, updatable = true, length = 16, precision = 0) @Basic public String getPhone1() { return itsPhone1; }
public void setPhone1(String inPhone1) { itsPhone1 = inPhone1; }
private String itsPhone2;
@Column (name = "phone2", nullable = true, insertable = true, updatable = true, length = 16, precision = 0) @Basic public String getPhone2() { return itsPhone2; }
public void setPhone2(String inPhone2) { itsPhone2 = inPhone2; }
private String itsFax;
@Column (name = "fax", nullable = true, insertable = true, updatable = true, length = 16, precision = 0) @Basic public String getFax() { return itsFax; }
public void setFax(String inFax) { itsFax = inFax; }
private String itsEmail;
@Column (name = "email", nullable = true, insertable = true, updatable = true, length = 128, precision = 0) @Basic public String getEmail() { return itsEmail; }
public void setEmail(String inEmail) { itsEmail = inEmail; }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false;
Address that = (Address) o;
if (itsAddressId != that.itsAddressId) return false; if (itsAddress1 != null ? !itsAddress1.equals(that.itsAddress1) : that.itsAddress1 != null) return false; if (itsAddress2 != null ? !itsAddress2.equals(that.itsAddress2) : that.itsAddress2 != null) return false; if (itsAddress3 != null ? !itsAddress3.equals(that.itsAddress3) : that.itsAddress3 != null) return false; if (itsCity != null ? !itsCity.equals(that.itsCity) : that.itsCity != null) return false; if (itsEmail != null ? !itsEmail.equals(that.itsEmail) : that.itsEmail != null) return false; if (itsFax != null ? !itsFax.equals(that.itsFax) : that.itsFax != null) return false; if (itsName != null ? !itsName.equals(that.itsName) : that.itsName != null) return false; if (itsPhone1 != null ? !itsPhone1.equals(that.itsPhone1) : that.itsPhone1 != null) return false; if (itsPhone2 != null ? !itsPhone2.equals(that.itsPhone2) : that.itsPhone2 != null) return false; if (itsZip != null ? !itsZip.equals(that.itsZip) : that.itsZip != null) return false;
return true; }
@Override public int hashCode() { int theresult = (int) (itsAddressId ^ (itsAddressId >>> 32)); theresult = 31 * theresult + (itsName != null ? itsName.hashCode() : 0); theresult = 31 * theresult + (itsAddress1 != null ? itsAddress1.hashCode() : 0); theresult = 31 * theresult + (itsAddress2 != null ? itsAddress2.hashCode() : 0); theresult = 31 * theresult + (itsAddress3 != null ? itsAddress3.hashCode() : 0); theresult = 31 * theresult + (itsCity != null ? itsCity.hashCode() : 0); theresult = 31 * theresult + (itsZip != null ? itsZip.hashCode() : 0); theresult = 31 * theresult + (itsPhone1 != null ? itsPhone1.hashCode() : 0); theresult = 31 * theresult + (itsPhone2 != null ? itsPhone2.hashCode() : 0); theresult = 31 * theresult + (itsFax != null ? itsFax.hashCode() : 0); theresult = 31 * theresult + (itsEmail != null ? itsEmail.hashCode() : 0); return theresult; }
private State itsState;
@ManyToOne @JoinColumn (name = "state_id", referencedColumnName = "state_id", nullable = false, table = "address") public State getState() { return itsState; }
public void setState(State inState) { itsState = inState; }
private Country itsCountry;
@ManyToOne @JoinColumn (name = "country_id", referencedColumnName = "country_id", nullable = false, table = "address") public Country getCountry() { return itsCountry; }
public void setCountry(Country inCountry) { itsCountry = inCountry; } }
The stack-trace:
Caused by: org.hibernate.AnnotationException: Cannot find the expected secondary table: no address available for test.Address at org.hibernate.cfg.Ejb3Column.getJoin(Ejb3Column.java:358) at org.hibernate.cfg.Ejb3Column.getTable(Ejb3Column.java:337) at org.hibernate.cfg.AnnotationBinder.bindManyToOne(AnnotationBinder.java:2627) at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1600) at org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:796) at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:707) at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3977) at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3931) at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1368) at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1345) at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:717) at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
|