srhmlpt wrote:
Do I need to provide more info? Or have I fumbled on to a question that has no answer ;) Please let me know.
I just built a test case around your mapping file and it worked fine for me. (Although I'm using 2.1.8 and hsqldb 1.7.2.)
Code:
public class UnresolvableObjectExceptionTest {
private static final Logger logger = Logger.getLogger(UnresolvableObjectExceptionTest.class);
static SessionFactory sessionFactory;
public static void main(String[] args) throws Exception {
UnresolvableObjectExceptionTest tester = new UnresolvableObjectExceptionTest();
tester.setUp();
tester.testUnresolvableObjectExceptionTest();
}
private void setUp() throws Exception {
Session session = getSession();
Transaction tx = session.beginTransaction();
B b1 = new B();
b1.setId(new Long(1));
b1.setB1("b1.B1");
session.save(b1);
C c1 = new C();
CKey ckey = new CKey();
ckey.setA3("a1.A3");
ckey.setA4("a1.A4");
c1.setCKey(ckey);
c1.setC1("c1.C1");
session.save(c1);
A a1 = new A();
a1.setA1(new Long(1234));
a1.setA3("a1.A3");
a1.setA4("a1.A4");
a1.setB(b1);
a1.setC(c1);
session.save(a1);
tx.commit();
session.close();
}
public void testUnresolvableObjectExceptionTest() throws Exception {
Session session = getSession();
logger.info("Test Starting.........");
String sql = "from A as a left join fetch a.c where a.a1 = :a1";
Query query = session.createQuery(sql);
query.setParameter("a1", new Long(1234));
List list = query.list();
for (Iterator i = list.iterator(); i.hasNext();) {
A a = (A) i.next();
System.out.println(a.getA1() + " " + a.getA3() + " " + a.getA4());
}
logger.info("Test Completed Successfully");
}
private Session getSession() throws Exception {
if (sessionFactory == null) {
Configuration cfg = new Configuration()
.addResource("test/uoe/Mapping.hbm.xml")
.setProperty("hibernate.connection.driver_class","org.hsqldb.jdbcDriver")
.setProperty("hibernate.connection.url", "jdbc:hsqldb:.")
.setProperty("hibernate.dialect", "net.sf.hibernate.dialect.HSQLDialect")
.setProperty("hibernate.connection.username", "sa")
.setProperty("hibernate.connection.password", "")
.setProperty("hibernate.connection.autocommit", "false")
.setProperty("hibernate.show_sql", "true")
.setProperty("hibernate.hbm2ddl.auto", "create-drop");
sessionFactory = cfg.buildSessionFactory();
}
return sessionFactory.openSession();
}
}
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="test.uoe" >
<class name="A" table="A" mutable="false">
<id name="a1" column="A1" type="java.lang.Long">
<generator class="assigned"/>
</id>
<many-to-one class="B" name="b" column="A2" not-null="false" outer-join="false" insert="false"/>
<property name="a3" column="A3" type="string" />
<property name="a4" column="A4" type="string" />
<many-to-one class="C" name="c" not-null="false" outer-join="true" insert="false" update="false">
<column name="A3"/>
<column name="A4" />
</many-to-one>
</class>
<class name="B" table="b">
<id name="id" column="A2" type="java.lang.Long">
<generator class="assigned"/>
</id>
<property name="b1" column="B1" type="string"/>
</class>
<class name="C" table="c">
<composite-id class="CKey" name="CKey">
<key-property name="a3" column="A3" type="string"/>
<key-property name="a4" column="A4" type="string"/>
</composite-id>
<property name="c1" column="C1" type="string"/>
</class>
</hibernate-mapping>