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.