开发者

Hibernate orm for a view

开发者 https://www.devze.com 2022-12-23 09:27 出处:网络
How do you ORM a view? Is there any difference with a table in terms of reverse engineering? In my case, I have a whole pile of joined tables that will be read-only in an application.

How do you ORM a view?

Is there any difference with a table in terms of reverse engineering?

In my case, I have a whole pile of joined tables that will be read-only in an application.

So, if I need sort of an Object with all collections in proper order, instead of long chains of relationships - collection with another etc, it'll be simpler.

开发者_如何学CWhat do you think and how do you accomplish this?


From the Hibernate docs: "There is no difference between a view and a base table for a Hibernate mapping." To map a view, in your orm.xml file you would simply need table = [your view name].

This is, incidentally, an artifact of the SQL standard that defines a view as a type of table, so they should operate just like a table (though many SQL vendors to not properly support INSERT and UPDATE on views). This means the same feature is likely to be supported by other ORM vendors.

As for whether or not it's a good idea, if you're already creating an ORM mapping for the raw tables, I would do as BalusC suggests (since you wouldn't need to create a object just to access a view). If the data is not being generated by your application so you don't already have an ORM mapping defined and you only need to access the view rather than the tables that compose the view, there's no reason not to just map the view.


Just obtain it as a collection of (nested) beans the usual Hibernate/DAO way, put it (in a bean?) in the request scope and let an iterating tag in the view layer iterate over it and use EL to display it. In JSTL for example you can use <c:forEach> to iterate over a (nested) collection.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号