title: How to have more than one mapping resource in the configuration file in hibernate?
body: <p>I have 2 POJO's Employee and Address and two tables employee and address. I am first trying to add an address row into the db and and then add an employee record with the reference of the address record added earlier. I can add the address record only when there is one mapping resource in the config file. </p>
  
  <p>My main file:`package many2one;</p>
  
  <pre><code>import org.hibernate.HibernateException;
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
  import org.hibernate.cfg.Configuration;
  import org.hibernate.service.ServiceRegistry;
  
  public class ManageEmployee {    
  /**
   * @param args the command line arguments
   */
  public static void main(String[] args) {
      // TODO code application logic here
      Session session = null;
      try
      {
          Configuration configuration = new Configuration();            
          configuration.configure("many2one/hibernate.cfg.xml");
          ServiceRegistry sr = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
          SessionFactory sf = configuration.buildSessionFactory(sr);
          session = sf.openSession();
          session.beginTransaction();
          System.out.println("Populating the Database.");
          Address1 address = new Address1("Mogappair","Chennai","Tamilnadu","600107");            
          session.save(address);           
          session.getTransaction().commit();
          System.out.println("Done");
      }catch(HibernateException he){
          System.out.println("Exception Thrown " + he);
      }finally{
          session.flush();
          session.close();
      }
  
  }
  
  }
  </code></pre>
  
  <p>My Employee POJO:</p>
  
  <pre><code>package many2one;
  import java.io.Serializable;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  
  @Entity(name="employee")
  public class Employee1 implements Serializable {
  private static final long serialVersionUID = 1L;
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  public Long id;
  public String firstName;
  public String lastName;
  public int salary;
  public Address1 address;
  
  public Employee1(){}
  
  public Employee1(String f_name,String l_name,int sal,Address1 add){
      this.firstName = f_name;
      this.lastName = l_name;
      this.salary = sal;
      this.address = add;
  }
  
  
  public Long getId() {
      return id;
  }
  
  public void setId(Long id) {
      this.id = id;
  }
  
  public String getFirstName(){
      return firstName;
  }
  
  public void setFirstName(String f_name){
      this.firstName = f_name;
  }
  
  public String getLastName(){
      return lastName;
  }
  
  public void setLastName(String l_name){
      this.lastName = l_name;
  }
  
  public Address1 getAddress(){
      return address;
  }
  
  public void setAddress(Address1 address){
      this.address = address;
  }
  
  
  }
  </code></pre>
  
  <p>My Address file</p>
  
  <pre><code>package many2one;
  
  import java.io.Serializable;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  
  @Entity(name="address")
  public class Address1 implements Serializable {
  private static final long serialVersionUID = 1L;
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  public Long id;
  public String streetName;
  public String cityName;
  public String stateName;
  public String zipcode;
  
  public Address1(){}
  public Address1(String s_name,String c_name,String st_name,String zipcode){
      this.streetName = s_name;
      this.cityName = c_name;
      this.stateName = st_name;
      this.zipcode = zipcode;
  }
  
  public Long getId() {
      return id;
  }
  
  public void setId(Long id) {
      this.id = id;
  }
  
  public String getStreetName() {
      return streetName;
  }
  
  public void setStreetName(String s_name) {
      this.streetName = s_name;
  }
  
  public String getCityName() {
      return cityName;
  }
  
  public void setCityName(String c_name) {
      this.cityName = c_name;
  }
  
  public String getStateName() {
      return stateName;
  }
  
  public void setStateName(String state_name) {
      this.stateName = state_name;
  }
  
  public String getZipcode() {
      return zipcode;
  }
  
  public void setZipcode(String zipcode) {
      this.zipcode = zipcode;
  }
  
  
  
  }
  </code></pre>
  
  <p>Config File:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate   Configuration DTD 3.0//EN" 
  "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"&gt;
  &lt;hibernate-configuration&gt;
   &lt;session-factory&gt;
   &lt;property  name="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
  &lt;property name="hibernate.connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
  &lt;property name="hibernate.connection.url"&gt;jdbc:mysql://localhost:3306/hibernate?zeroDateTimeBehavior=convertToNull&lt;/property&gt;
  &lt;property name="hibernate.connection.username"&gt;root&lt;/property&gt;
  &lt;!--&lt;mapping resource="many2one/Mapping.hbm.xml"/&gt;--&gt;
  &lt;mapping resource="many2one/Address1.hbm.xml"/&gt;
  &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>Mapping File:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
  "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"&gt;
  &lt;hibernate-mapping&gt;
  &lt;class name="many2one.Employee1" table="employee"&gt;
  &lt;meta attribute="class-description"&gt;
    This contains the Employee Details
  &lt;/meta&gt;    
  &lt;id name="id" column="id" type="long"&gt;
    &lt;generator class="native"&gt;&lt;/generator&gt;
  &lt;/id&gt;
    &lt;property name="firstName" column="first_name" type="string"&gt;&lt;/property&gt;
    &lt;property name="lastName" column="last_name" type="string"&gt;&lt;/property&gt;
    &lt;property name="salary" column="salary" type="string"&gt;&lt;/property&gt;
    &lt;many-to-one name="address" column="address" class="many2one.Address1" not-null="true"/&gt;
    &lt;/class&gt;
    &lt;class name="many2one.Address1" table="address"&gt;
    &lt;meta attribute="class-description"&gt;
        This contains the Address Details
    &lt;/meta&gt;
    &lt;id name="id" column="id" type="long"&gt;
        &lt;generator class="native"&gt;&lt;/generator&gt;
    &lt;/id&gt;
    &lt;property name="streetName" column="street_name" type="string"&gt;&lt;/property&gt;
    &lt;property name="cityName" column="city_name" type="string"&gt;&lt;/property&gt;
    &lt;property name="stateName" column="state_name" type="string"&gt;&lt;/property&gt;
    &lt;property name="zipcode" column="zipcode" type="string"&gt;&lt;/property&gt;
    &lt;/class&gt;  
  
    &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>My task is to add an address record in the database and then add an employee record using the employee constructor with the address reference. I am able to add the address record when the mapping resource for employee table is commented out but if I try to do both then I get an error. Could not get constructor error.</p>
  
  <p>StackTrace:`debug:</p>
  
  <pre><code>Feb 26, 2015 11:19:10 AM org.hibernate.annotations.common.reflection.java.JavaReflectionManager &lt;clinit&gt;
  
  INFO: HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
  Feb 26, 2015 11:19:11 AM org.hibernate.Version logVersion
  INFO: HHH000412: Hibernate Core {4.3.1.Final}
  Feb 26, 2015 11:19:11 AM org.hibernate.cfg.Environment &lt;clinit&gt;
  INFO: HHH000206: hibernate.properties not found
  Feb 26, 2015 11:19:11 AM org.hibernate.cfg.Environment buildBytecodeProvider
  INFO: HHH000021: Bytecode provider name : javassist
  Feb 26, 2015 11:19:12 AM org.hibernate.cfg.Configuration configure
  INFO: HHH000043: Configuring from resource: many2one/hibernate.cfg.xml
  Feb 26, 2015 11:19:12 AM org.hibernate.cfg.Configuration getConfigurationInputStream
  INFO: HHH000040: Configuration resource: many2one/hibernate.cfg.xml
  Feb 26, 2015 11:19:12 AM org.hibernate.cfg.Configuration addResource
  INFO: HHH000221: Reading mappings from resource: many2one/Mapping.hbm.xml
  Feb 26, 2015 11:19:13 AM org.hibernate.cfg.Configuration doConfigure
  INFO: HHH000041: Configured SessionFactory: null
  Feb 26, 2015 11:19:15 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
  WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!)
  Feb 26, 2015 11:19:16 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
  INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/hibernate?zeroDateTimeBehavior=convertToNull]
  Feb 26, 2015 11:19:16 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
  INFO: HHH000046: Connection properties: {user=root}
  Feb 26, 2015 11:19:16 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
  INFO: HHH000006: Autocommit mode: false
  Feb 26, 2015 11:19:16 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
  INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
  Feb 26, 2015 11:19:17 AM org.hibernate.dialect.Dialect &lt;init&gt;
  INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
  Feb 26, 2015 11:19:18 AM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
  INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
  Feb 26, 2015 11:19:18 AM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory &lt;init&gt;
  INFO: HHH000397: Using ASTQueryTranslatorFactory
  Feb 26, 2015 11:19:19 AM org.hibernate.validator.internal.util.Version &lt;clinit&gt;
  INFO: HV000001: Hibernate Validator 5.0.0.Final
  Exception Thrown org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
  </code></pre>
  
  <p>`</p>
  
  <p>`</p>