-->
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.  [ 3 posts ] 
Author Message
 Post subject: Select query correct but wrong mapping
PostPosted: Tue May 18, 2004 4:45 am 
Regular
Regular

Joined: Tue May 04, 2004 6:15 am
Posts: 51
Hi there,

Hibernate 2.1.3

Mapping document
Code:
<class name="Location" table="destinations" polymorphism="explicit">
        <id name="abbreviation"  column="dabbr"  type="java.lang.String"  unsaved-value="null"  length="32">
            <generator class="hilo"/>
        </id>

        <property name="name" column="dname" type="java.lang.String" not-null="true"/>
       
        <set name="destinations" cascade="all" inverse="false" lazy="false">
           <key column="dabbr" />
           <one-to-many class="Area" />
        </set>
</class>

<class name="Area" table="areas" polymorphism="explicit">
   <id name="abbreviation"  column="aabbr"  type="java.lang.String"  unsaved-value="null"  length="32">
       <generator class="hilo"/>
    </id>

    <property name="name" column="aname" type="java.lang.String" not-null="true"/>
       
    <many-to-one name="parent" class="Location" column="dabbr" />
</class>


part of HiberDatabase Class

Code:
   private static SessionFactory sessionFactory = null;
   private static Session session = null;
      
   static
   {
      try
      {
         System.out.println("Initializing Hibernate");         
         sessionFactory = new Configuration().configure().buildSessionFactory();
         
         System.out.println("Finished Initializing Hibernate");
      }
      catch (HibernateException e)
      {
         e.printStackTrace();
      }      
   }
    
   private static ResultSet performQuery(String sql, String[] args)
   {
      Connection connection;
      PreparedStatement statement;
      ResultSet resultSet = null;   
      
      try
      {
         if(session == null || !session.isOpen())
            session = sessionFactory.openSession();
                        
            
         connection = session.connection();
         statement = connection.prepareStatement(sql);          
                  
         if(args != null)
         {
            for(int argument = 1; argument <= args.length; argument++)
               statement.setString(argument, args[argument-1]);//argument list starts at 1 but array from 0
         }
            
         resultSet = statement.executeQuery();
      }
      catch (Exception e)
      {
         System.out.println( e.getMessage() );
         resultSet = null;
         
         try
         {
            session.close();
         }
         catch (HibernateException e1)
         {
            e1.printStackTrace();
            session.clear();
         }
      }
      
   return resultSet;
   }
   
   public static List find(String hql)
   {
      try
      {         
         if(session == null || !session.isOpen())
            session = sessionFactory.openSession();
            
         Transaction tx = session.beginTransaction();
         
         List result = session.find(hql);
            
         tx.commit();
         session.close();
         
      return result;
      }
      catch (HibernateException e)
      {
         throw new RuntimeException(e.getMessage());
      }
   }


Statements executing under Sybase 11.9.2.3
Code:
select distinct location0_.dabbr as dabbr, location0_.dname as dname from destinations location0_

select destinatio0_.aabbr as aabbr__, destinatio0_.dabbr as dabbr__, destinatio0_.aabbr as aabbr0_, destinatio0_.aname as aname0_, destinatio0_.dabbr as dabbr0_ from areas destinatio0_ where destinatio0_.dabbr=?


Although the above statements are correct and work for every value, I noticed that for the Location object with dabbr = 'GRATH' the one of the corresponding Areas has aabbr = 'GRRNO' which is wrong. (could be for other Locations as well, didn't check all)

Any clues as to what might be causing this?
Thanks.

_________________
eu:life
http://www.eulife.gr


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 18, 2004 5:56 am 
Regular
Regular

Joined: Tue May 04, 2004 6:15 am
Posts: 51
arg!!!!!!!!!!!!!!

I just noticed that Area abbreviation is not 'GRRNO' but 'TOW' for some crazy idea that i'm unfamiliar with, most of Areas that refer to town have 'TOW' as their abbreviation!!!!!!!!!!!!!

Therefore, the many-to-one relationship works in mysterious ways! Though the select statement is correct.

So should i change this to many-to-many? Is there a workaround for this?

The 2 select statements shown above are the correct ones for sure.

Please? :(

_________________
eu:life
http://www.eulife.gr


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 18, 2004 6:08 am 
Regular
Regular

Joined: Tue May 04, 2004 6:15 am
Posts: 51
Removed the "aabbr" from the <id> element and now hibernate doesn't use it for the mapping i guess.

Case closed...

_________________
eu:life
http://www.eulife.gr


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