0

In my Java program with Hibernate I have XML file with two Named Query:

<hibernate-mapping>
    <sql-query name="BIG_SQL_QUERY_WITH_LOT_OF_WHERE">
       <![CDATA[
         select * from Foo
         where ...
           and ...
           and ...
           ...
         order by ...
       ]]>
    </sql-query>

    <sql-query name="BIG_SQL_QUERY_WITH_LOT_OF_WHERE_WITH_ONE_MORE_CONDITION">
       <![CDATA[
         select * from Foo
         where ...
           and ...
           and ...
           ...
           and one_more_condition = ...
         order by ...
       ]]>
</hibernate-mapping>

First query ("BIG_SQL_QUERY_WITH_LOT_OF_WHERE") has a lot of join and conditions inside. Second query ("BIG_SQL_QUERY_WITH_LOT_OF_WHERE_WITH_ONE_MORE_CONDITION") is the same query but it has one more where condition.

Is it any way to make one query with common part of this query and use in them (or include) only this one part of second query (only this one more condition)?

1 Answer 1

1

Pure XML solution: you could use a XML entity, that is an abbreviated entry you can place anywhere in your XML document:

<?xml version="1.0" standalone="no" ?>
<!DOCTYPE hibernate-mapping [
<!ENTITY includedStuff SYSTEM "common.xml">
]>
<hibernate-mapping>
    <sql-query name="BIG_SQL_QUERY_WITH_LOT_OF_WHERE">
       &includedStuff;
    </sql-query>
</hibernate-mapping>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.