aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate Query Returns Duplicate Rows Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate Query Returns Duplicate Rows" Watch "Hibernate Query Returns Duplicate Rows" New topic
Author

Hibernate Query Returns Duplicate Rows

Casey Kcins
Greenhorn

Joined: Mar 12, 2007
Posts: 16
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

Joined: Mar 12, 2007
Posts: 16
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

Joined: Feb 05, 2001
Posts: 17249
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Casey Kcins
Greenhorn

Joined: Mar 12, 2007
Posts: 16
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

Joined: Feb 05, 2001
Posts: 17249
    
    6

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

Joined: Mar 12, 2007
Posts: 16
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate Query Returns Duplicate Rows
 
Similar Threads
How to put List in hibernate Query
How data stored in Database
Escape HQL Like special characters
EJB with Hibernate
accessing parent of child