Hibernate ORM when using many to one mapping without class attribute
Ashish Kumar Ashok
Joined: Aug 08, 2012
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.
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
Joined: Jan 04, 2012
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.