-->
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.  [ 4 posts ] 
Author Message
 Post subject: session.get() yields different result than a findbyCiteria.
PostPosted: Wed Jan 10, 2007 12:04 pm 
Newbie

Joined: Sun Apr 04, 2004 4:22 am
Posts: 7
Code:
      TableDefinition refTable = XXXTestData.createReferenceTable();
      xxxService.storeObject(refTable);
      Map criteria1 = new HashMap();
      criteria1.put("technicalId", refTable.getTechnicalId());
      TableDefinition tb3 = (TableDefinition) xxxService.findByCriteria(TableDefinition.class, criteria1).get(0);
      TableDefinition tb4 = (TableDefinition) xxxService.getObjectById(TableDefinition.class, refTable.getTechnicalId());




tb3 is not null while tb4 is null...any suggestions???


The methods:
Code:
   /**
    * Get object by id
    * @param objectClass
    * @param technicalId
    * @return
    */
   public Object getObjectById(Class objectClass, Long technicalId) {
      Object result = null;
      try {
         result = getCurrentSession().get(objectClass, technicalId);
         if (result == null) {
            throw new KeyNotFoundException("No object of class " + objectClass.getName() + " found  with id = " + technicalId);
         }
   
      } catch (HibernateException exception) {
         throw new TechnicalException(
            new StringBuffer("A Hibernate exception occurred when trying to retrieve an object of class \"")
               .append(objectClass.getName())
               .append("\" with id: ")
               .append(technicalId)
               .toString(),
            exception);
      }
      return result;
   }
   /**
    *
    * method
    * @see com.ing.itrf.sdm.persistence.SdmDAO#findByCriteria(java.lang.Class, java.util.Map)
    */
   public List findByCriteria(Class clazz, Map criteria) {
      List result = null;
      Criteria criteriaObject = getCurrentSession().createCriteria(clazz);
      Iterator it = criteria.keySet().iterator();
      while (it.hasNext()) {
         String criterion = (String) it.next();
         criteriaObject.add(Expression.eq(criterion, criteria.get(criterion)));
      }
      result = criteriaObject.list();
      return result;
   }


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 10, 2007 5:05 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
what results? what's the error? is the sql generated in the logs the same? is the sama data in the logs returned?

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 10, 2007 11:09 pm 
Newbie

Joined: Sun Apr 04, 2004 4:22 am
Posts: 7
kochcp wrote:
what results? what's the error? is the sql generated in the logs the same? is the sama data in the logs returned?

Thanks for your reaction.
1. The result: tb3 equals refTable(they have the same id)
tb4 equals null
2. There is no error.
3. The same sql is generated.
4. Not the same data return, see 1.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 11, 2007 3:11 am 
Newbie

Joined: Sun Apr 04, 2004 4:22 am
Posts: 7
The SQL statements

Code:

      TableDefinition tb3 = (TableDefinition) xxxService.findByCriteria(TableDefinition.class, criteria1).get(0);
yields:

select
        this_.technical_id as technical1_67_0_,
        this_.technical_version as technical2_67_0_,
        this_.valid_from as valid3_67_0_,
        this_.valid_until as valid4_67_0_,
        this_.definition_version as definition5_67_0_,
        this_.display_name as display6_67_0_,
        this_.distribution_name as distribu7_67_0_,
        this_.description as descript8_67_0_,
        this_.has_hierarchy as has9_67_0_,
        this_.max_hierarchy_level as max10_67_0_,
        this_.is_proposal as is11_67_0_,
        this_.is_visible as is12_67_0_,
        this_.can_distribute as can13_67_0_,
        this_.creation_requester as creation14_67_0_,
        this_.creation_approver as creation15_67_0_,
        this_.creation_request_date as creation16_67_0_,
        this_.creation_approval_date as creation17_67_0_,
        this_.last_change_requester as last18_67_0_,
        this_.last_change_approver as last19_67_0_,
        this_.last_change_request_date as last20_67_0_,
        this_.last_change_approval_date as last21_67_0_,
        this_.last_distribution_date as last22_67_0_,
        this_.attributes_category as attributes23_67_0_,
        this_.mappings_category as mappings24_67_0_,
        this_.table_authorization_id as table25_67_0_,
        this_.status as status67_0_,
        this_1_.target_table_definition_id as target2_68_0_,
        this_1_.action as action68_0_,
        this_1_.proposal_status as proposal4_68_0_,
        decode(this_.technical_id,
        this_1_.table_definition_id,
        1,
        0) as clazz_0_
    from
        TABLE_DEFINITION this_,
       STRUCTURE_PROPOSAL this_1_
    where
        this_.technical_id=this_1_.table_definition_id(+)
        and this_.technical_id=?


AND

Code:

      TableDefinition tb4 = (TableDefinition) xxxService.getObjectById(TableDefinition.class, refTable.getTechnicalId());
yields

Hibernate:
    select
        tabledefin0_.technical_id as technical1_67_0_,
        tabledefin0_.technical_version as technical2_67_0_,
        tabledefin0_.valid_from as valid3_67_0_,
        tabledefin0_.valid_until as valid4_67_0_,
        tabledefin0_.definition_version as definition5_67_0_,
        tabledefin0_.display_name as display6_67_0_,
        tabledefin0_.distribution_name as distribu7_67_0_,
        tabledefin0_.description as descript8_67_0_,
        tabledefin0_.has_hierarchy as has9_67_0_,
        tabledefin0_.max_hierarchy_level as max10_67_0_,
        tabledefin0_.is_proposal as is11_67_0_,
        tabledefin0_.is_visible as is12_67_0_,
        tabledefin0_.can_distribute as can13_67_0_,
        tabledefin0_.creation_requester as creation14_67_0_,
        tabledefin0_.creation_approver as creation15_67_0_,
        tabledefin0_.creation_request_date as creation16_67_0_,
        tabledefin0_.creation_approval_date as creation17_67_0_,
        tabledefin0_.last_change_requester as last18_67_0_,
        tabledefin0_.last_change_approver as last19_67_0_,
        tabledefin0_.last_change_request_date as last20_67_0_,
        tabledefin0_.last_change_approval_date as last21_67_0_,
        tabledefin0_.last_distribution_date as last22_67_0_,
        tabledefin0_.attributes_category as attributes23_67_0_,
        tabledefin0_.mappings_category as mappings24_67_0_,
        tabledefin0_.table_authorization_id as table25_67_0_,
        tabledefin0_.status as status67_0_,
        tabledefin0_1_.target_table_definition_id as target2_68_0_,
        tabledefin0_1_.action as action68_0_,
        tabledefin0_1_.proposal_status as proposal4_68_0_,
        decode(tabledefin0_.technical_id,
        tabledefin0_1_.table_definition_id,
        1,
        0) as clazz_0_
    from
        TABLE_DEFINITION tabledefin0_,
        STRUCTURE_PROPOSAL tabledefin0_1_
    where
        tabledefin0_.technical_id=tabledefin0_1_.table_definition_id(+)
        and tabledefin0_.technical_id=?

technical_id is the identifying column or primairy key of the table


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.