I am getting this error:
Quote:
Unable to resolve path [DBO_Contacts.xid], unexpected token [DBO_Contacts] ...
my HBM lookes like:
Code:
<class name="DBO_ContactInfo" table="ContactInfo">
<id name="id" column="id">
<generator class="native"/>
</id>
<one-to-one name="xid" class="DBO_Contacts" fetch="join"/>
<property name="ContactInfo"/>
<property name="Private"/>
</class>
Code:
Session newSession = HibernateUtil.getSessionFactory().openSession();
List<DBO_ContactInfo> messages = (List<DBO_ContactInfo>)newSession.createQuery("from DBO_ContactInfo where DBO_Contacts.xid=20").list();
newSession.close();
This produces that error...how do I fetch a set of (emails, phones) from ContactInfo which is joined to Contacts (Last, First, Middle, Title) based upon something in the Contacts table?
Also if I do this:
Code:
Session newSession = HibernateUtil.getSessionFactory().openSession();
List<DBO_ContactInfo> messages = (List<DBO_ContactInfo>)newSession.createQuery().list();
newSession.close();
It produces multiple queries instead of one
Quote:
select contactinf0_.xid as xid3_, contactinf0_.id as id3_, contactinf0_.id as id25_2_, contactinf0_.ContactInfo as ContactI2_25_2_, contactinf0_.Private as Private25_2_, dbo_contac1_.id as id24_0_, dbo_contac1_.xid as xid24_0_, dbo_contac1_.Last as Last24_0_, dbo_contac1_.First as First24_0_, dbo_contac1_.Middle as Middle24_0_, dbo_contac1_.Title as Title24_0_, dbo_tconta2_.id as id11_1_, dbo_tconta2_.ContactType as ContactT2_11_1_ from ContactInfo contactinf0_ left outer join Contacts dbo_contac1_ on contactinf0_.id=dbo_contac1_.id left outer join tContactType dbo_tconta2_ on dbo_contac1_.id=dbo_tconta2_.id where contactinf0_.xid=? order by contactinf0_.Type asc
with the problem being the added where contactInf0_.xid=?
instead of just this:
Code:
mysql> select * from Contacts;
+----+------+-------+-------+--------+-------+------+
| id | xid | Last | First | Middle | Title | Type |
+----+------+-------+-------+--------+-------+------+
| 1 | 20 | Foo | Bar | W | NULL | 1 |
| 2 | 22 | Smith | John | NULL | NULL | NULL |
+----+------+-------+-------+--------+-------+------+
mysql> select * from ContactInfo;
+----+------+----------------+------+---------+
| id | xid | ContactInfo | Type | Private |
+----+------+----------------+------+---------+
| 1 | 1 | foo@bar.org | 8 | NULL |
| 2 | 2 | john@smith.com | 8 | NULL |
| 11 | 1 | 111-222-3333 | 2 | NULL |
+----+------+----------------+------+---------+
mysql> select * from ContactInfo, Contacts where ContactInfo.xid = Contacts.id;
+----+------+----------------+------+---------+----+------+-------+-------+--------+-------+------+
| id | xid | ContactInfo | Type | Private | id | xid | Last | First | Middle | Title | Type |
+----+------+----------------+------+---------+----+------+-------+-------+--------+-------+------+
| 1 | 1 | foo@bar.org | 8 | NULL | 1 | 20 | Foo | Bar | W | NULL | 1 |
| 11 | 1 | 111-222-3333 | 2 | NULL | 1 | 20 | Foo | Bar | W | NULL | 1 |
| 2 | 2 | john@smith.com | 8 | NULL | 2 | 22 | Smith | John | NULL | NULL | NULL |
+----+------+----------------+------+---------+----+------+-------+-------+--------+-------+------+
The 3rd one being the desired join.