Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate ORM when using many to one mapping without class attribute

 
Ashish Kumar Ashok
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to use <many-to-one name="test" class="com.myproject.model.test.TestDTO" column="test_id"/> in a hbm.xml file. But the problem is that I am only using <sql-query> tags in hibernate mapping for testDTO.hbm.xml and I do not have the mapping <class> tag that maps my DTO and the table from the database. Because of this I get an error saying that "An association from the table xxxx refers to an unmapped class: com.myproject.model.test.TestDTO". How do I go about solving the problem? I am trying to solve this by not trying to include the <class> mapping.

 
Alexander Bondarev
Greenhorn
Posts: 12
 
Ashish Kumar Ashok
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply . Let me give you a detailed description of my issue

Below is the first hibernate mapping file (DFormDTO.hbm.xml). It has the associated POJO DFormDTO


Below is the second hibernating mapping file (CaptureDTO.hbm.xml). As you can see there is no <class> tag which maps objects (com.model.capture.CaptureDTO) to relation (capture). It is only using hibernate named queries.


Since there is no <class> tag in the above hibernate mapping file it was throwing the "An association from the table X refers to an unmapped class". I was wondering if there was a way to solve the issue. I was not planning to add the <class> tag and the associated <property> tags for CaptureDTO.hbm.xml though (which will in fact solve the issue)

In order to solve the issue for my project I replaced the DFormDTO.hbm.xml with the below code. I had the remove the <many-to-one> mapping




 
Alexander Bondarev
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you have done right. If you use mapping with hbm.xml files then Hibernate will map only properties which are listed in the hbm.xml file. If you don't need mapping then your property should be omited in the hbm.xml file.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic