Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Query Returns Duplicate Rows

 
Casey Kcins
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay. I have a weird question I was wondering if someone can help me out with. I have a method that's job is basically to return the entire table. It works, but returns the same row twice. Is there something I'm doing wrong with the iterator?



So... any ideas why I'm getting twice as many rows? Do you need to see any more code then I've displayed?
 
Casey Kcins
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, well that's really weird.
The Database name is Appointment

I have an Appointment class, and a DoctorsAppointment class (which extends Appointment).

When I set up my query (from Appointment), for some reason, it grabbed it for both Appointment, and DoctorsAppointment. Which doubled the result.

When I queried (from DoctorsAppointment), which is not the name of the table, I got the correct result set.

Huh.

-- Casey Kcins
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you declare inheritance mapping, the type of mapping you do will change the type of query that is run, if you use <union-subclass> (table per implemented subclass) the query will unionize the subclass tables into one result set, which might cause your duplicate rows. a <joined-subclass> (third normal form data tables) will do a join between the parent and child tables, which might be more of what you are looking for, and finally <subclass> is for a single table.

What do your tables look like, and how did you map them?

mark
 
Casey Kcins
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I actually didn't map the parent class to the subclass.
I had no idea that was something you should do until you mentioned it.
Then I looked it up http://www.hibernate.org/hib_docs/reference/en/html/inheritance.html

When I set it up in the application, I only called the subclass (DoctorsAppointment). There isn't a use for the main class really.

There won't be any subclasses to the main class (Appointment), so I don't think I'll need to do that mapping.

Good to know though.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Casey Kcins:
I actually didn't map the parent class to the subclass.
I had no idea that was something you should do until you mentioned it.
Then I looked it up http://www.hibernate.org/hib_docs/reference/en/html/inheritance.html

When I set it up in the application, I only called the subclass (DoctorsAppointment). There isn't a use for the main class really.

There won't be any subclasses to the main class (Appointment), so I don't think I'll need to do that mapping.


I'm confused, you made a Appointment class then subclassed it with DoctorsAppointment, but you don't ever expect to need to subclass Appointment ever again, no DentistsAppointment, or AccountantAppointment?

If that is the case, my question is why have that Appointment superclass?

Mark
Good to know though.
 
Casey Kcins
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If that is the case, my question is why have that Appointment superclass?

Neurosis?

No. It bothered me that since I was making a many-to-one relationship with the doctor class, I needed to reference Doctor in Appointment. But... It may not necisarrily be a 'doctors appointment'. Even though there may never be another subclass, it just felt right creating one to reference the Doctor class.

<shrugs>

-- Casey Kcins
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic