-->
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.  [ 5 posts ] 
Author Message
 Post subject: Mapping interfaces
PostPosted: Fri Jan 27, 2006 10:27 am 
Newbie

Joined: Fri Jan 27, 2006 10:14 am
Posts: 2
Hibernate version: 3.1.1
Name and version of the database you are using: Oracle 9i


I have a class that implements two differents interfaces..... I want to know how to do the mapping in this case.



public class Document implements IPrintable, IExportable {
..
..
}


Thank.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 27, 2006 11:39 am 
Beginner
Beginner

Joined: Mon Jan 23, 2006 12:01 pm
Posts: 46
Are you saying you have two tables (TABLE_PRINTABLE and TABLE_EXPORTABLE), and you want to map both to a single Java class?

Or are you saying that you have a Java class that implements two different interfaces, and maps to a single table (TABLE_DOCUMENT)?

In the first case, take a look at joined-subclass element of the Hibernate mapping file (hbm.xml).

In the second case, nothing special needs to be done. Hibernate deals with tables, so you can map whatever fields from Document to your Oracle table as you see fit.

HTH,

Bratek


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 27, 2006 12:46 pm 
Newbie

Joined: Fri Jan 27, 2006 10:14 am
Posts: 2
Thank you for your answer, it's ok. Our case is the second one.

Now, supose that you have:


public class Document implements IPrintable {
..
..
}

public class Template implements IPrintable {
..
..
}

public class Link {
..
private IPrintable printable;
..
}



And the new question is: How to map the class Link?.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 27, 2006 12:51 pm 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
Hello Lucas,

please read the hibernate reference one time cross over. This is a typical standard mapping. (components).

Regards Sebastian

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 27, 2006 1:17 pm 
Beginner
Beginner

Joined: Mon Jan 23, 2006 12:01 pm
Posts: 46
What I would suggest you do instead is take a look at this page:

http://www.hibernate.org/hib_docs/tools/ant/index.html

Then use hibernatetool <hbm2hbmxml> ant task to import hibernate mapping from an existing db schema (I'm assuming you're working with an existing database - if not, there is another tool to create the db from your Java objects, but I've never tried it).
That way you will see what Hibernate thinks of your mappings (mappings for all tables will be generated for you), and you will have a good start on tweaking those. It's much easier than writing all mappings from scratch, especially if you have many tables.

I would let Hibernate import your schema first. And then use another Hibernate task to create Java objects from mappings (<hbm2java>). That way you will see what Java classes are created by codegen. It could be that it might be better to place Link inside Document and Template, not the other way around.

HTH,

Bratek


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.