-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: MappingException during Hybernate Configuration run
PostPosted: Wed May 26, 2010 1:33 pm 
Newbie

Joined: Wed May 26, 2010 1:23 pm
Posts: 2
I am fairly new to Hibernate and tried to use Configuration in Eclipse, but got the following error:

org.hibernate.MappingException: An association from the table template_periods refers to an unmapped class: com.nb.pi.db.beans.Template

This happened after I changed class name to be fully qualified (com.nb.pi.db.beans.Template).

I look on the hbm and Java files that were generated and they look fine to me. Could somebody tell me what might be wrong?

Please see code below.

Thanks in advance.

Code:
<hibernate-mapping>
    <class name="Template" table="template" schema="dbo" catalog="pi">
        <id name="templateId" type="long">
            <column name="template_id" precision="15" scale="0" />
            <generator class="identity" />
        </id>
        <property name="templateName" type="string">
            <column name="template_name" length="50" not-null="true" />
        </property>
        <property name="updateDate" type="date">
            <column name="update_date" length="10" not-null="true" />
        </property>
        <property name="updatedBy" type="string">
            <column name="updated_by" length="50" not-null="true" />
        </property>
        <property name="grossNet" type="java.lang.Character">
            <column name="gross_net" length="1" />
        </property>
        <property name="periodicity" type="java.lang.Character">
            <column name="periodicity" length="1" />
        </property>
        <property name="sectorNo" type="java.lang.Integer">
            <column name="sector_no" />
        </property>
        <property name="sortPeriod" type="java.lang.Integer">
            <column name="sort_period" />
        </property>
        <property name="sortStatistic" type="java.lang.Integer">
            <column name="sort_statistic" />
        </property>
        <set name="templatePeriods" inverse="true" lazy="true" table="template_periods" fetch="select">
            <key>
                <column name="template_id" precision="15" scale="0" not-null="true" />
            </key>
            <one-to-many class="TemplatePeriods" />
        </set>
        <set name="templateStats" inverse="true" lazy="true" table="template_stats" fetch="select">
            <key>
                <column name="template_id" precision="15" scale="0" not-null="true" />
            </key>
            <one-to-many class="TemplateStats" />
        </set>
        <set name="templateProducts" inverse="true" lazy="true" table="template_products" fetch="select">
            <key>
                <column name="template_id" precision="15" scale="0" not-null="true" />
            </key>
            <one-to-many class="TemplateProducts" />
        </set>
    </class>
</hibernate-mapping>

<hibernate-mapping>
    <class name="TemplatePeriods" table="template_periods" schema="dbo" catalog="pi">
        <composite-id name="id" class="com.nb.pi.db.beans.TemplatePeriodsId">
            <key-property name="templateId" type="long">
                <column name="template_id" precision="15" scale="0" />
            </key-property>
            <key-property name="seqNo" type="int">
                <column name="seq_no" />
            </key-property>
        </composite-id>
        <many-to-one name="template" class="com.nb.pi.db.beans.Template" update="false" insert="false" fetch="select">
            <column name="template_id" precision="15" scale="0" not-null="true" />
        </many-to-one>
        <property name="periodType" type="string">
            <column name="period_type" length="10" not-null="true" />
        </property>
        <property name="trailingNo" type="java.lang.Integer">
            <column name="trailing_no" />
        </property>
        <property name="calendarFrom" type="java.lang.Integer">
            <column name="calendar_from" />
        </property>
        <property name="calendarTo" type="java.lang.Integer">
            <column name="calendar_to" />
        </property>
        <property name="customFrom" type="date">
            <column name="custom_from" length="10" />
        </property>
        <property name="customTo" type="string">
            <column name="custom_to" length="25" />
        </property>
    </class>
</hibernate-mapping>

package com.nb.pi.db.beans;

import java.util.Date;
import java.util.HashSet;

/**
* Template generated by hbm2java
*/
public class Template implements java.io.Serializable {

   /**
    *
    */
   private static final long serialVersionUID = -6841587574836601287L;
   private long templateId;
   private String templateName;
   private Date updateDate;
   private String updatedBy;
   private Character grossNet;
   private Character periodicity;
   private Integer sectorNo;
   private Integer sortPeriod;
   private Integer sortStatistic;
   private HashSet<TemplatePeriods> templatePeriods = new HashSet<TemplatePeriods>(0);
   private HashSet<TemplateStats> templateStats = new HashSet<TemplateStats>(0);
   private HashSet<TemplateProducts> templateProducts = new HashSet<TemplateProducts>(0);

   public Template() {
   }

   public Template(long templateId, String templateName, Date updateDate,
         String updatedBy) {
      this.templateId = templateId;
      this.templateName = templateName;
      this.updateDate = updateDate;
      this.updatedBy = updatedBy;
   }

   public Template(long templateId, String templateName, Date updateDate,
         String updatedBy, Character grossNet, Character periodicity,
         Integer sectorNo, Integer sortPeriod, Integer sortStatistic,
         HashSet<TemplatePeriods> templatePeriods, HashSet<TemplateStats> templateStats, HashSet<TemplateProducts> templateProducts) {
      this.templateId = templateId;
      this.templateName = templateName;
      this.updateDate = updateDate;
      this.updatedBy = updatedBy;
      this.grossNet = grossNet;
      this.periodicity = periodicity;
      this.sectorNo = sectorNo;
      this.sortPeriod = sortPeriod;
      this.sortStatistic = sortStatistic;
      this.templatePeriods = templatePeriods;
      this.templateStats = templateStats;
      this.templateProducts = templateProducts;
   }

   public long getTemplateId() {
      return this.templateId;
   }

   public void setTemplateId(long templateId) {
      this.templateId = templateId;
   }

   public String getTemplateName() {
      return this.templateName;
   }

   public void setTemplateName(String templateName) {
      this.templateName = templateName;
   }

   public Date getUpdateDate() {
      return this.updateDate;
   }

   public void setUpdateDate(Date updateDate) {
      this.updateDate = updateDate;
   }

   public String getUpdatedBy() {
      return this.updatedBy;
   }

   public void setUpdatedBy(String updatedBy) {
      this.updatedBy = updatedBy;
   }

   public Character getGrossNet() {
      return this.grossNet;
   }

   public void setGrossNet(Character grossNet) {
      this.grossNet = grossNet;
   }

   public Character getPeriodicity() {
      return this.periodicity;
   }

   public void setPeriodicity(Character periodicity) {
      this.periodicity = periodicity;
   }

   public Integer getSectorNo() {
      return this.sectorNo;
   }

   public void setSectorNo(Integer sectorNo) {
      this.sectorNo = sectorNo;
   }

   public Integer getSortPeriod() {
      return this.sortPeriod;
   }

   public void setSortPeriod(Integer sortPeriod) {
      this.sortPeriod = sortPeriod;
   }

   public Integer getSortStatistic() {
      return this.sortStatistic;
   }

   public void setSortStatistic(Integer sortStatistic) {
      this.sortStatistic = sortStatistic;
   }

   public HashSet<TemplatePeriods> getTemplatePeriods() {
      return this.templatePeriods;
   }

   public void setTemplatePeriods(HashSet<TemplatePeriods> templatePeriods) {
      this.templatePeriods = templatePeriods;
   }

   public HashSet<TemplateStats> getTemplateStats() {
      return this.templateStats;
   }

   public void setTemplateStats(HashSet<TemplateStats> templateStats) {
      this.templateStats = templateStats;
   }

   public HashSet<TemplateProducts> getTemplateProducts() {
      return this.templateProducts;
   }

   public void setTemplateProducts(HashSet<TemplateProducts> templateProducts) {
      this.templateProducts = templateProducts;
   }

}

package com.nb.pi.db.beans;

import java.util.Date;

/**
* TemplatePeriods generated by hbm2java
*/
public class TemplatePeriods implements java.io.Serializable {

   /**
    *
    */
   private static final long serialVersionUID = -7214992812593458011L;
   private TemplatePeriodsId id;
   private Template template;
   private String periodType;
   private Integer trailingNo;
   private Integer calendarFrom;
   private Integer calendarTo;
   private Date customFrom;
   private String customTo;

   public TemplatePeriods() {
   }

   public TemplatePeriods(TemplatePeriodsId id, Template template,
         String periodType) {
      this.id = id;
      this.template = template;
      this.periodType = periodType;
   }

   public TemplatePeriods(TemplatePeriodsId id, Template template,
         String periodType, Integer trailingNo, Integer calendarFrom,
         Integer calendarTo, Date customFrom, String customTo) {
      this.id = id;
      this.template = template;
      this.periodType = periodType;
      this.trailingNo = trailingNo;
      this.calendarFrom = calendarFrom;
      this.calendarTo = calendarTo;
      this.customFrom = customFrom;
      this.customTo = customTo;
   }

   public TemplatePeriodsId getId() {
      return this.id;
   }

   public void setId(TemplatePeriodsId id) {
      this.id = id;
   }

   public Template getTemplate() {
      return this.template;
   }

   public void setTemplate(Template template) {
      this.template = template;
   }

   public String getPeriodType() {
      return this.periodType;
   }

   public void setPeriodType(String periodType) {
      this.periodType = periodType;
   }

   public Integer getTrailingNo() {
      return this.trailingNo;
   }

   public void setTrailingNo(Integer trailingNo) {
      this.trailingNo = trailingNo;
   }

   public Integer getCalendarFrom() {
      return this.calendarFrom;
   }

   public void setCalendarFrom(Integer calendarFrom) {
      this.calendarFrom = calendarFrom;
   }

   public Integer getCalendarTo() {
      return this.calendarTo;
   }

   public void setCalendarTo(Integer calendarTo) {
      this.calendarTo = calendarTo;
   }

   public Date getCustomFrom() {
      return this.customFrom;
   }

   public void setCustomFrom(Date customFrom) {
      this.customFrom = customFrom;
   }

   public String getCustomTo() {
      return this.customTo;
   }

   public void setCustomTo(String customTo) {
      this.customTo = customTo;
   }

}




Top
 Profile  
 
 Post subject: Re: MappingException during Hybernate Configuration run
PostPosted: Wed May 26, 2010 1:41 pm 
Newbie

Joined: Wed May 26, 2010 1:23 pm
Posts: 2
One more comment: if I change class name in Template file to be fully qualified as
class name="com.nb.pi.db.beans.Template"
It throws a different exception in Session Factory during refersh of configuration.

Quote:
Problems while creating sessionfactory

org.hibernate.MappingException: An association from the table template_periods refers to an unmapped class: com.nb.pi.db.beans.Template
at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1252)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1170)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1286)
at org.hibernate.console.ConsoleConfiguration$3.execute(ConsoleConfiguration.java:492)
at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:64)
at org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:94)
at org.hibernate.console.ConsoleConfiguration.buildSessionFactory(ConsoleConfiguration.java:487)
at org.hibernate.eclipse.console.workbench.LazySessionFactoryAdapter.getChildren(LazySessionFactoryAdapter.java:43)
at org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.getChildren(BasicWorkbenchAdapter.java:99)
at org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.fetchDeferredChildren(BasicWorkbenchAdapter.java:105)
at org.eclipse.ui.progress.DeferredTreeContentManager$1.run(DeferredTreeContentManager.java:234)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.