简体   繁体   中英

How to create hbm.xml file for mysql view and how to add it in hibernate configuration?

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?

Got the answer:

I created the hibernate mapping ie 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM