I'm using an sql-query because I want to join on a table which hasn't yet been mapped in hibernate. My simple test, which loads a single mapped object, works but leaves session.isDirty() = true. Peeking inside the session reveals that there are no actions in actionQueue: in fact, the only field in session which has data is persistenceContext.entitiesByKey, which has the two objects I've just queried for. Curiously, it reports its size as being 3, even though there are only 2 items in it.
My query is: why is the session dirty and what do I change to leave it clean after the query? It's causing exceptions in my non-test code. Here are the details:
Hibernate version:
3.06
Mapping documents (extracts):
Code:
<class name="IssueImpl" table="Issue">
<meta attribute="implements">
com.energyintellect.manage.issue.Issue
</meta>
<id name="IssueID" type="int">
<generator class="identity"/>
</id>
<property name="Open" column="IssueStateOpen"
type="boolean" not-null="true">
</property>
<property name="Description" column="Description"
type="string" not-null="true"/>
</class>
<class name="LoggerIssue" table="LoggerIssue">
<id name="IssueID" column="IssueID" type="int">
<generator class="foreign">
<param name="property">Issue</param>
</generator>
</id>
<one-to-one name="Issue" class="IssueImpl" constrained="true"
lazy="false"/>
<property name="LoggerID" column="LoggerID" type="string"/>
</class>
<sql-query name="LoggerIssuesByStatePartition">
<return alias="li" class="LoggerIssue" lock-mode="read"/>
select {li.*}
from Logger l
inner join LoggerIssue li on l.loggerID = li.loggerID
where l.PartitionID = :PartitionID
</sql-query>
Logger is the unmapped table. LoggerIssue.LoggerID is a foreign key referring to Logger.LoggerID.
Code between sessionFactory.openSession() and session.close():Code:
Query qry = session().getNamedQuery("LoggerIssuesByStatePartition");
qry.setParameter("PartitionID", getPartitionURN());
List<LoggerIssue> issues = (List<LoggerIssue>) qry.list();
Name and version of the database you are using:SQLServer 2000
The generated SQL (show_sql=true):Code:
Query qry = session().getNamedQuery("LoggerIssuesByStatePartition");
qry.setParameter("PartitionID", getPartitionURN());
List<LoggerIssue> issues = (List<LoggerIssue>) qry.list();