-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Hibernate generates duplicate queries at runtime
PostPosted: Wed Apr 16, 2014 12:22 pm 
Newbie

Joined: Wed Apr 16, 2014 12:05 pm
Posts: 2
Hi All,

I am currently evaluating this framework for my new project. I am facing an issue with duplicate queries being created/executed by hibernate for the following tables:

Code:
CREATE TABLE QueryCondition (QueryID INT not null references Query(QueryID), ConditionNumber INT not null, LogicalOperator INT NULL, Parent INT NULL,
primary key (QueryID, ConditionNumber)
)

CREATE TABLE QueryConditionValue (QueryID INT not null ,
ConditionNumber INT not null , RelationalOperator INT not null, TableName VARCHAR(50) not null, ColumnName VARCHAR(50) not null, Value VARCHAR(1800) not null,
primary key (QueryID, ConditionNumber,RelationalOperator,TableName,  ColumnName),
Foreign key (QueryID, ConditionNumber) references QueryCondition(QueryID, ConditionNumber)
)


Hbm files generated by the tool for these two tables (showing here only the association and keys)

QueryCondition

Code:
<composite-id name="id" class="com.xyz.model.QueryConditionId">
            <key-property name="queryId" type="int">
                <column name="QueryID" />
            </key-property>
            <key-property name="conditionNumber" type="int">
                <column name="ConditionNumber" />
            </key-property>
</composite-id>
<set name="queryConditionValues" table="QueryConditionValue" inverse="true" lazy="false" fetch="select">
            <key>
                <column name="QueryID" not-null="true" />
                <column name="ConditionNumber" not-null="true" />
            </key>
            <one-to-many class="com.xyz.model.QueryConditionValue" />
</set>


QueryConditionValues
Code:
    <composite-id name="id" class="com.xyz.model.QueryConditionValueId">
            <key-property name="queryId" type="int">
                <column name="QueryID" />
            </key-property>
            <key-property name="conditionNumber" type="int">
                <column name="ConditionNumber" />
            </key-property>
            <key-property name="relationalOperator" type="int">
                <column name="RelationalOperator" />
            </key-property>
            <key-property name="tableName" type="string">
                <column name="TableName" length="50" />
            </key-property>
            <key-property name="columnName" type="string">
                <column name="ColumnName" length="50" />
            </key-property>
        </composite-id>

        <many-to-one name="queryCondition" class="com.xyz.model.QueryCondition" update="false" insert="false" fetch="select">
            <column name="QueryID" not-null="true" />
            <column name="ConditionNumber" not-null="true" />
        </many-to-one>


Queries generated at run time:

Code:
Hibernate: select querycondi0_.QueryID as QueryID1_0_0_, querycondi0_.QueryID as QueryID1_2_0_, querycondi0_.ConditionNumber as ConditionNumber2_2_0_, querycondi0_.QueryID as QueryID1_2_1_, querycondi0_.ConditionNumber as ConditionNumber2_2_1_, querycondi0_.LogicalOperator as LogicalOperator3_2_1_, querycondi0_.Parent as Parent4_2_1_ from CDB.dbo.QueryCondition querycondi0_ where querycondi0_.QueryID=?


Duplicate queries starts here. Also each column appears three times in select statement
Code:
Hibernate: select querycondi0_.QueryID as QueryID1_2_0_, querycondi0_.ConditionNumber as ConditionNumber2_2_0_, querycondi0_.QueryID as QueryID1_3_0_, querycondi0_.ConditionNumber as ConditionNumber2_3_0_, querycondi0_.RelationalOperator as RelationalOperator3_3_0_, querycondi0_.TableName as TableName4_3_0_, querycondi0_.ColumnName as ColumnName5_3_0_, querycondi0_.QueryID as QueryID1_3_1_, querycondi0_.ConditionNumber as ConditionNumber2_3_1_, querycondi0_.RelationalOperator as RelationalOperator3_3_1_, querycondi0_.TableName as TableName4_3_1_, querycondi0_.ColumnName as ColumnName5_3_1_, querycondi0_.Value as Value6_3_1_ from CDB.dbo.QueryConditionValue querycondi0_ where querycondi0_.QueryID=? and querycondi0_.ConditionNumber=?

Hibernate: select querycondi0_.QueryID as QueryID1_2_0_, querycondi0_.ConditionNumber as ConditionNumber2_2_0_, querycondi0_.QueryID as QueryID1_3_0_, querycondi0_.ConditionNumber as ConditionNumber2_3_0_, querycondi0_.RelationalOperator as RelationalOperator3_3_0_, querycondi0_.TableName as TableName4_3_0_, querycondi0_.ColumnName as ColumnName5_3_0_, querycondi0_.QueryID as QueryID1_3_1_, querycondi0_.ConditionNumber as ConditionNumber2_3_1_, querycondi0_.RelationalOperator as RelationalOperator3_3_1_, querycondi0_.TableName as TableName4_3_1_, querycondi0_.ColumnName as ColumnName5_3_1_, querycondi0_.Value as Value6_3_1_ from CDB.dbo.QueryConditionValue querycondi0_ where querycondi0_.QueryID=? and querycondi0_.ConditionNumber=?

Hibernate: select querycondi0_.QueryID as QueryID1_2_0_, querycondi0_.ConditionNumber as ConditionNumber2_2_0_, querycondi0_.QueryID as QueryID1_3_0_, querycondi0_.ConditionNumber as ConditionNumber2_3_0_, querycondi0_.RelationalOperator as RelationalOperator3_3_0_, querycondi0_.TableName as TableName4_3_0_, querycondi0_.ColumnName as ColumnName5_3_0_, querycondi0_.QueryID as QueryID1_3_1_, querycondi0_.ConditionNumber as ConditionNumber2_3_1_, querycondi0_.RelationalOperator as RelationalOperator3_3_1_, querycondi0_.TableName as TableName4_3_1_, querycondi0_.ColumnName as ColumnName5_3_1_, querycondi0_.Value as Value6_3_1_ from CDB.dbo.QueryConditionValue querycondi0_ where querycondi0_.QueryID=? and querycondi0_.ConditionNumber=?

Hibernate: select querycondi0_.QueryID as QueryID1_2_0_, querycondi0_.ConditionNumber as ConditionNumber2_2_0_, querycondi0_.QueryID as QueryID1_3_0_, querycondi0_.ConditionNumber as ConditionNumber2_3_0_, querycondi0_.RelationalOperator as RelationalOperator3_3_0_, querycondi0_.TableName as TableName4_3_0_, querycondi0_.ColumnName as ColumnName5_3_0_, querycondi0_.QueryID as QueryID1_3_1_, querycondi0_.ConditionNumber as ConditionNumber2_3_1_, querycondi0_.RelationalOperator as RelationalOperator3_3_1_, querycondi0_.TableName as TableName4_3_1_, querycondi0_.ColumnName as ColumnName5_3_1_, querycondi0_.Value as Value6_3_1_ from CDB.dbo.QueryConditionValue querycondi0_ where querycondi0_.QueryID=? and querycondi0_.ConditionNumber=?


Would appreciate your help here in understanding and resolving this issue.

Kind Regards


Top
 Profile  
 
 Post subject: Re: Hibernate generates duplicate queries at runtime
PostPosted: Wed Apr 16, 2014 1:03 pm 
Newbie

Joined: Wed Apr 16, 2014 12:05 pm
Posts: 2
I think I know why it is like that. After looking at the table values, and as per the schema, it will generate a sql for each QueryID+ConditionNumber. QueryCondition table has four rows for its master table key and hence it creates 4 queries for its child table too.

However, why does it select the same column multiple times in the SQL? I see that it is applicable to key columns only.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.