Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What to do with queries which don´t have a representation in a domain model?

Tags:

orm

This is not specific to any language, it´s just about best practices. I am using JPA/Hibernate (but it could be any other ORM solution) and I would like to know how do you guys deal with this situation: Let´s suppose that you have a query returning something that is not represented by any of your domain classes. Do you create a specific class to represent that specific query? Do you return the query in some other kind of object (array, map...) Some other solutions? I would like to know about your experiences and best practices.

P.S. Actually I am creating specific objetcs for specific queries.

like image 538
Ivan Bosnic Avatar asked Nov 15 '22 17:11

Ivan Bosnic


1 Answers

We have a situation that sounds similar to yours.

We use separate objects for reporting data that spans several domain objects. Our convention is that these will be backed by a view in the database, so we have come to call them view objects. We generally use them for summarising complex data into a flat format.

like image 152
Dave Richardson Avatar answered Jun 17 '23 19:06

Dave Richardson