File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Hibernate ORM when using many to one mapping without class attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate ORM when using many to one mapping without class attribute" Watch "Hibernate ORM when using many to one mapping without class attribute" New topic
Author

Hibernate ORM when using many to one mapping without class attribute

Ashish Kumar Ashok
Greenhorn

Joined: Aug 08, 2012
Posts: 2
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

Joined: Jan 04, 2012
Posts: 12
You can look at Mapping of entities without tables and Hibernate entities without underlying tables.
Ashish Kumar Ashok
Greenhorn

Joined: Aug 08, 2012
Posts: 2
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

Joined: Jan 04, 2012
Posts: 12
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate ORM when using many to one mapping without class attribute