This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

mapping for subclass - forcing query to join-

 
Joshua Kay
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic