• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

mapping for subclass - forcing query to join-

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
2 DB tables - EMPLOYEE, PERSON
2 Classes - EMPLOYEE, PERSON

Employee extends Person

Mapping document for Employee.hbm.xml shows Employee as a subclass:

<joined-subclass name="Employee" table="EMPLOYEE" extends="Person">
<key column="guid_id" />

There are 50,000 PERSON records, but only 10,000 EMPLOYEE records.

The query is "from PERSON p"

It creates the SQL join correctly, except that it adds (+) at the end - which effectively renders the join useless, and it returns all 50,000 records.

I am sure I am missing something very basic.

Any takers?

thx
Josh
 
Joshua Kay
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<sigh> I meant to say the mapping for Person.hbm.xml, *not* Employee.hbm.xml

Essentially - I want to query the Person object to return a list of all Employees.

As Employee is more specific than Person, this is probably not the best way. How would I map the Person to the Employee in the Employee.hbm.xml?

(the first post still stands as my primary question, but I am willing to take any advice)

thx
Josh
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since you are explicitely looking for Employees, why not use "from Employee e ..."?
 
Joshua Kay
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is some information which is in the Person table which I need, hence the join.

If I select "from Employee e..." do I still use the same mapping file that shows Employee as a subclass of Person? *or* do I need to use the Employee.hbm.xml file, and add something to it which shows off its relationship to Person (class Employee extends Person)

Like I said, I am probably missing something obvious. Thanks for the reply-
Josh
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From reading the docs on inheritence, I'd say you leave Employee's mappings inside Person's mapping file and simply change your query. Querying for Employees should still allow you to mention Person's properties since Employee is-a Person.

Have you tried it? If so, what happened?
 
Joshua Kay
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, David.

I changed
Configuration cfg = new Configuration().addClass(Employee.class);
to
Configuration cfg = new Configuration().addClass(Person.class);

It now works, correctly (it seems). I was just going to the wrong mapping file.

Like I said above, I was missing something basic.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic