java - org.hibernate.MappingException: Could not determine type for: (foo) -


i have 2 classes being managed hibernate, classa , classb. classa has reference classb. according documentation hibernate should able type through reflection. can't understand why doesn't work. missing fundamental here?

this classa marked @entity annotation , holding reference classb.

package dom;  import javax.persistence.entity; import javax.persistence.id;  @entity public class classa {      private classb classb;      private long id;              public classa() {};      public classb getclassb() {         return classb;     }      public void setclassb(classb classb) {         this.classb = classb;     }      @id     public long getid() {         return id;     }      public void setid(long id) {         this.id = id;     }     } 

this classb marked @enity annotation.

package dom;  import javax.persistence.entity; import javax.persistence.id;  @entity public class classb {      private long id;      @id     public long getid() {         return id;     }      public void setid(long id) {         this.id = id;     }  } 

i following stack trace:

caused by: org.hibernate.mappingexception: not determine type for: dom.classb, @ table: classa, columns: [org.hibernate.mapping.column(classb)]         @ org.hibernate.mapping.simplevalue.gettype(simplevalue.java:316)         @ org.hibernate.mapping.simplevalue.isvalid(simplevalue.java:294)         @ org.hibernate.mapping.property.isvalid(property.java:238)         @ org.hibernate.mapping.persistentclass.validate(persistentclass.java:469)         @ org.hibernate.mapping.rootclass.validate(rootclass.java:270)         @ org.hibernate.cfg.configuration.validate(configuration.java:1294)         @ org.hibernate.cfg.configuration.buildsessionfactory(configuration.java:1742)         @ org.hibernate.cfg.configuration.buildsessionfactory(configuration.java:1788)         @ org.springframework.orm.hibernate4.localsessionfactorybuilder.buildsessionfactory(localsessionfactorybuilder.java:247)         @ org.springframework.orm.hibernate4.localsessionfactorybean.buildsessionfactory(localsessionfactorybean.java:373)         @ org.springframework.orm.hibernate4.localsessionfactorybean.afterpropertiesset(localsessionfactorybean.java:358)         @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.invokeinitmethods(abstractautowirecapablebeanfactory.java:1541)         @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1479) 

you need annotate field @onetoone (assuming isn't @manytoone, i.e. many classb can contain many classa's) annotation:

@onetoone private classb classb; 

this should minimum code needed add relation between entities.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -