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)
QueryConditionCode:
<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