java - Hibernate one-to-many mapping configuration -


i new hibernate , trying implement one-to-many relationship cascade loading , updating. however, code generates org.apache.jasper.jasperexception: org.hibernate.mappingexception: not constructor org.hibernate.persister.entity.singletableentitypersister exception. take on attempt , suggest doing wrong?

the general idea there company class contains set of customers. when creating new instance of customer, add him company , persist everything.

entities (only displaying relevant parts, or @ least hope so)

public class company implements serializable {      private static final long serialversionuid = 146243652;      private string id;     private string name;     private string website;     private set<customer> customers;     ... getters, setters etc  public class customer implements serializable {     private static final long serialversionuid = 864235654;      private string name;     private string surname;     private string adress;     private string id;     private company company; 

customer.hbm.xml:

<hibernate-mapping>     <class name="wa2.entities.customer" table="customer">         <id column="id" name="id" type="java.lang.string" />         <property column="name" name="name" type="java.lang.string" />         <property column="surname" name="surname" type="java.lang.string" />         <property column="adress" name="adress" type="java.lang.string" />           <many-to-one name="company" class="wa2.entities.company">              <column name="company_id" not-null="true"></column>           </many-to-one>      </class> </hibernate-mapping> 

company.hbm.xml:

<?xml version="1.0" encoding="utf-8"?> <!doctype hibernate-mapping public "-//hibernate/hibernate mapping dtd 3.0//en" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping>     <class name="wa2.entities.company" table="company">         <id column="id" name="id" type="java.lang.string" />         <property column="name" name="name" type="java.lang.string" />         <property column="website" name="website" type="java.lang.string" />          <set name="customers" table="customer" fetch="select">             <key>                 <column name="customer_id" not-null="true"></column>             </key>             <one-to-many class="wa2.entities.customer"/>         </set>     </class> </hibernate-mapping> 

saving customer (this worked before implementation of one-to-many relationship doubt there wrong code):

        customer customer = new customer();          string name = req.getparameter("name");         customer.setname(name);         string surname = req.getparameter("surname");         customer.setsurname(surname);         string adress = req.getparameter("adress");         customer.setadress(adress);          string companyid = req.getparameter("companyid");         company company = repository.loadcompany(companyid);         customer.setcompany(company);          string id = uuid.randomuuid().tostring();         customer.setid(id);          repository.savecustomer(customer); 

i hope did not forget relevant part. if so, please tell me , post relevant code. thank help!

edit: responses. seems wrote names wrongly in capitals. changed , getting failed lazily initialize collection of role: wa2.entities.company.customers, not initialize proxy - no session

since mapping exception, guess comes during session factory creation, , not when saving? also, seeing whole stacktrace help. exception can caused mismatch of property names between mapping file , beans. see could not constructor org.hibernate.persister.entity.singletableentitypersister.

in code have name attribute values in

<many-to-one name="company" class="wa2.entities.company">     <column name="company_id" not-null="true"></column>  </many-to-one> 

and

<set name="customers" table="customer" fetch="select">      <key>         <column name="customer_id" not-null="true"></column>      </key>      <one-to-many class="wa2.entities.customer"/>  </set> 

in uppercase, while properties in pojos named company , customer.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -