-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: interfaces in 'Getting Parents and Children to Play Nice'
PostPosted: Thu Jul 28, 2005 1:21 pm 
Newbie

Joined: Thu Jul 22, 2004 11:23 am
Posts: 14
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:2.1.7
Mapping documents:N/A
Code between sessionFactory.openSession() and session.close():N/A
Full stack trace of any exception that occurs:N/A
Name and version of the database you are using:MySQL 4.0.21
The generated SQL (show_sql=true):N/A
Debug level Hibernate log excerpt:N/A
---------------
Hi,

I have a question about the use of interfaces as described in the article "Getting Parents and Children to Play Nice" found on the hibernate site at: http://www.hibernate.org/209.html.

In this example, they show using an interface "GenericJob" as the type for a Set property, which is what I also want to do. However, in the example, they specify the class in the one-to-many as an implementor of that interface named "ChildJobClass", and it's mentioned later that the table-per-subclass polymorphism strategy is used between the interface and implementors. The example seems to imply that only one class that implements that "GenericJob" interface can be inserted into this set, as that single class is specified in the one-to-many element.

I want to be able to do something similar, but I want to be able to insert any of several different classes that implement my interface into the set and have the set be able to contain any assorted group of classes that implement the interface. Is this possible? Also, is it *necessary* to use the table-per-subclass polymorphism strategy, or could another strategy be used? I've been trying to make this work with a many-to-many implemented as suggested in HIA as 2 one-to-many/many-to-one relationships to an intervening entity class but was getting strange results so I've decide to just see if I can implement a simple Set first. If hibernate doesn't support putting several different classes that implement an interface into a Set I'd like to find out before I waste a bunch of time trying to make it work. I can't find anything that addresses this directly, but can this be done? If so, how? I was thinking that I could specify the interface class in the one-to-many element in the parent's hbm file but would hibernate know what implementing class it was dealing with at runtime in that case via reflection? I'm going to try this but I have this feeling I'm missing something here, any help would be appreciated!

Thanks in advance!!

-=j=-


Top
 Profile  
 
 Post subject: re:interfaces in 'Getting Parents and Children to Play Nice'
PostPosted: Wed Aug 03, 2005 12:27 pm 
Newbie

Joined: Thu Jul 22, 2004 11:23 am
Posts: 14
Well, I can answer my own question. At the very least, XDoclet doesn't support interfaces using the table-per-subclass mapping strategy. As soon as I changed the "implements" keyword to "extends" and made the requisite code changes to switch from an interface to inheritance, xdoclet generated my mapping without issue, putting the joined-subclass elemts into the mapping file for the superclass. With the interface, xdoclet simply didn't generate the joined-subclass at all which left the implementing classes without a mapping element and which then caused hibernate to puke on an unmapped class.

I've also heard that the interface thing *can* work, but that the speaker who told me this claimed that he had to write and maintain the mapping manually rather than maintain it via xdoclet. As the use of inheritance instead of an interface isn't *much* more limiting where it occurs in my model, I've chosen to use inheritance and be able to keep the whole mapping process working completely via xdoclet rather than encumber our dev process with a manual mapping at this point. I believe it's in the original post but this was found using xdoclet 1.2.2 & hibernate 2.1.7 -- I've found a definite xdoclet issue, but haven't the time to verify that interfaces work with hibernate. Interfaces *ARE* very poorly documented WRT hibernate, that's for sure, I'd love to see a more thorough and authoritative discussion.

-=j=-


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.