Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate mapping

 
Fix Berg
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to Hibernate, Trying to join 2 tables one-to-many

BusUnit.java:

public class BusUnit implements Serializable{

private static final long serialVersionUID = 1L;

private String busUnit;
private String psBusUnit;
private String legalEnt;
private Date startDate;
private Date endDate;
private String lastUpdtUsr;
private Date lastUpdtDt;
private BusUnitDesc busUnitDesc;

.......


BusUnitDesc.java

public class BusUnitDesc implements Serializable{

private static final long serialVersionUID = 1L;

private String busUnit;
private String busUnitDesc;
private Set<BusUnit> busUnits = new HashSet<BusUnit>(0);

BusUnit.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.common.db.busunit.BusUnit" table="TRSRV_PS_BUS_UNIT">
<composite-id>
<key-property name="legalEnt" column="LEGAL_ENTITY"></key-property>
<key-property name="busUnit" column="BUS_UNIT"></key-property>
<key-property name="startDate" column="START_DT"></key-property>
</composite-id>
<property name="endDate">
<column name="END_DT" />
</property>
<property name="psBusUnit">
<column name="PS_BUS_UNIT"/>
</property>
<property name="lastUpdtUsr">
<column name="LAST_UPDATE_USR_ID"/>
</property>
<property name="lastUpdtDt">
<column name="LAST_UPDATE_TS"/>
</property>
<many-to-one name="busUnitDesc" class="BusUnitDesc">
<column name="PS_BUS_UNIT" not-null="true" />
</many-to-one>


</class>
</hibernate-mapping>

BusUnitDesc.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.common.db.busunit.BusUnitDesc" table="TRSRV_PS_BU_DESC">
<id name="busUnit" type="string">
<column name="PS_BUS_UNIT" />
<generator class="assigned" />
</id>
<property name="busUnitDesc">
<column name="PS_BUS_UNIT_DESC" />
</property>
<set name="busUnits" table="TRSRV_PS_BUS_UNIT"
inverse="true" lazy="true">
<key>
<column name="PS_BUS_UNIT"/>
</key>
<one-to-many class="com.common.db.busunit.BusUnit" />
</set>
</class>
</hibernate-mapping>

hibernate.cfg.xml:
....
<mapping resource="resources/com/common/busunit/BusUnit.hbm.xml"/>
<mapping resource="resources/com/common/busunit/BusUnitDesc.hbm.xml"/>

Getting exception while running the following code: sessionFactory = config.buildSessionFactory();

org.hibernate.MappingException: An association from the table TRSRV_PS_BUS_UNIT refers to an unmapped class: BusUnitDesc

Any idea why I am getting it?
Thank you


 
rohit chavan
Ranch Hand
Posts: 132
Hibernate Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Fix,

Please use "code tags", in order to make your query readable for others.

As far as your query is concerned, IMO you need to provide the fully qualified name for the class BusUnitDesc.

In mapping file for BusUnit.java
Instead of

use the the class name like below, (taken from your post irself)



Hope this helps.
 
Fix Berg
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rohit.

That was it. Thank you!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic