This week's book giveaway is in the Beginning Java forum.
We're giving away four copies of Get Programming with Java (MEAP only) and have Peggy Fisher on-line!
See this thread for details.
Win a copy of Get Programming with Java (MEAP only) this week in the Beginning Java 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
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Hibernate mapping  RSS feed

 
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


 
Ranch Hand
Posts: 133
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!
 
It means our mission is in jeapordy! Quick, read this tiny ad!
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!