-->
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: mapping an interface?
PostPosted: Mon Aug 07, 2006 3:56 am 
Senior
Senior

Joined: Sun Jun 11, 2006 10:41 am
Posts: 164
Hi all,
I have the following object model:
Code:
public interface Component {
   void start();
   void stop();
}

public class MyComp implements Component {
...
}

public class Server {
   Component comp;
   void setComponent(Component c) { comp = c; }
// component is a part of the server, but may vary in implementation
}


Let's also assume all components are in a single table (COMPONENT) with a discriminator column (CLASS).

How do I create mapping files for this object model? Hibernate forces me to provide an 'id' in the Component.hbm.xml file, but obviously, I do not want to expose any id-handling in this interface... I'd rather keep it private in the MyComp implementation.

Hibernate version:
3.1

Mapping documents:

Code between sessionFactory.openSession() and session.close():
Server s1 = new Server();
s1.setComponent(new MyComp());

Full stack trace of any exception that occurs:

Name and version of the database you are using:
HSQLDB 1.8.0.4

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 07, 2006 11:43 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Read up on the table per class hierarchy polymorphism implementation strategy. Specify only classes in your mapping files, not interfaces. As you are implementing table per class hierarchy, obviously all implementations have the same ID and discriminator, at least: make a ComponentImpl class that includes these, and have all your component implementations extend that.

You can also specify abstract="true" on your top-level mapping, and specify the id element in all concrete mappings. That's a waste of effort, IMO.

_________________
Code tags are your friend. Know them and use them.


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.