Question

I have created mysql view for two tables which are in different schema using JDBC, because hibernate is not providing any facility do the same. I am using entity_mode as dynamic-map, so I have to create hibernate configuration by adding documents of hbm.xml files of all my entities from my schema.

My question is, how do I create hbm.xml for view? Because it has some different structure than the other hbm.xml files of entities. How to add view mapping to the hibernate configuration, So I can do at least read operations using hibernate queries?

Is this possible in hibernate? If yes then how can I achieve this?

Was it helpful?

Solution

Got the answer:

I created the hibernate mapping i.e. hbm.xml file for view by using standard templates of hbm file and add it to hibernate configuration object. But for mapping, hibernate must need one id field in the hbm.xml file to work, so that I have to made one of the id field from both tables as the id field of the view and it worked.

It is giving the multiple result because the id is repeated, So you need to have two constraints for the view query so it will give you unique result. This is weird but it is the simplest and only way to acquire the same.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top