-->
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.  [ 8 posts ] 
Author Message
 Post subject: Is possible to map class, when table not exists?
PostPosted: Tue Aug 10, 2004 10:40 am 
Beginner
Beginner

Joined: Thu Apr 29, 2004 4:03 pm
Posts: 40
Hi guys,

I really tried to found the answer myself, but I'm not wiser after reading the documentation:
My problem is:

I want to map a class, but no table exist for that class.

Class Segment {}
Class MyType{}

Class SegmentR extends Segment {
Integer id
Collection myCollectionOfMyTypes
}

I want to map SegmentR, something like this:
<class segmentR>
<bag><one to many MyType></one-to-many> </bag>
</class>

I want to do this, because other subclasses have tables, but this one doesn't , and I want to write general methods, not distinguishing the concrete subclass. Simply, to be as transparen as I can. Thanks.

p.s. to hibernate team: don't give up ;)


Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 10, 2004 2:04 pm 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
I guess you're looking for a inheritance mapping. Chapters 5.1.13, 5.1.14 of the reference manual have more infos about this.
The new Hibernate in Action Book has also a very nice description in chapter 3.6.

HTH
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 10, 2004 3:36 pm 
Beginner
Beginner

Joined: Thu Apr 29, 2004 4:03 pm
Posts: 40
ernst_pluess wrote:
I guess you're looking for a inheritance mapping. Chapters 5.1.13, 5.1.14 of the reference manual have more infos about this.
The new Hibernate in Action Book has also a very nice description in chapter 3.6.

HTH
Ernst


I don't think so.
Clearly, it's possible to declare a parent-child relationship where no table exists for parent.

But I don't see any possibility to declare a composition relationship(so Parent contains some type), where no table exists for parent.

Please, if you know any solution, post it.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 11, 2004 2:04 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Do I get you right? SegmentR acts as a template for subclasses. There will probably never be an instance of type SegmentR (if yes, using abstract class or interface is a good idea).

Best Regards
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 11, 2004 4:37 am 
Beginner
Beginner

Joined: Thu Apr 29, 2004 4:03 pm
Posts: 40
ernst_pluess wrote:
Do I get you right? SegmentR acts as a template for subclasses. There will probably never be an instance of type SegmentR (if yes, using abstract class or interface is a good idea).

Best Regards
Ernst


no...

ok, I'll try to explain it simplier:

I have a class, let's say MyClass. Myclass contains some objectc, which are mapped in hibernate, and works 100% fine.

But there is no table for myclass. Altought, I want to define it in Hibernate. I want to tell hibernate:
Here's MyClass, which has these object types. If I tell load(Myclass), create an instance of myClass, and load all it's objects. If I say save(myClass), don't do anything, or throw an exception.

I know, It's possible to say
<class name="thisClassDoesNotHaveTable">
<subclass name"butThisOneHas">

but I want to map:
<class "thisClassWithNoTable>
<property name="ClassWithTable" type....>

any idea?is it possible?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 11, 2004 4:54 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Ok, I got it!

I don't think Hibernate suports this, but I'm not 100% sure. (Can one of the experts confirm this?)

You could do this by using the DAO pattern.

Let's assume you have MyParent-->MyChild, with no table for MyParent (which means it's not persistent).

For MyParent write a InMemoryMyParentDAO, for the MyChild write a HibernateMyChildDAO. Now the InMemoryMyParentDAO can load its children via the HibernateMyChildDAO in the getter method. I think would be to hard to even implement a kind of cascade all between the two.

HTH
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 11, 2004 5:17 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
No, this is not possible. How should hibernate know which objects are associated to your MyClass. You can only load classes which have actually a table associated (or are superclasses of persistent classes, via polymorphic queries)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 11, 2004 11:02 am 
Beginner
Beginner

Joined: Thu Apr 29, 2004 4:03 pm
Posts: 40
michael wrote:
No, this is not possible. How should hibernate know which objects are associated to your MyClass.


ok, thanks both of you guys.


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