Win a copy of Pipeline as Code this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Hibernate mapping

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
Ranch Hand
Posts: 133
Hibernate Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rohit.

That was it. Thank you!
 
It's hard to fight evil. The little things, like a nice sandwich, really helps. Right tiny ad?
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic