Question

I have two tables in my DB, T1 and T2. One column of T1 is a foreign key that references T2. I need only a part of the columns of T1 and T2 for my processing, thus I've created a DTO T1T2 that contains only the necessary columns. To map the DTO to these two tables with Hibernate, I used subselect attribute of the class element.

<hibernate-mapping>
<class
    name="com.xconnect.cdrrecorder.processing.dto.IngressNumRuleVoipProfile"
    table="numbermodificationrules"
    subselect="select ... from T1 left join T2 on id1=id2 where ...">

    <cache usage="read-only"/>

...

</class>
</hibernate-mapping>

I noticed that when i need to select for an object, Hibernate converts the request to two selects (one into the other).

Is there a better way to do this? What do you think about performances?

Thanks

Was it helpful?

Solution

If you are creating a DTO, better to fill the DTO from the query as in an example here. Only create the entity if there are backing tables.

If the DTO is used very often you can write a view in the DB and create a simple DTO entity to refer that. Since view is pre-compiled in the DB, it will be faster.

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