-->
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.  [ 1 post ] 
Author Message
 Post subject: sql-query with simple join is leaving a dirty session.
PostPosted: Mon Jun 13, 2005 1:59 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
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();


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

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.