-->
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.  [ 4 posts ] 
Author Message
 Post subject: Many-to-one between table and component objects
PostPosted: Thu Mar 30, 2006 10:24 pm 
Newbie

Joined: Mon Nov 21, 2005 1:48 pm
Posts: 17
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0

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:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Is it possible to have a many-to-one relationship between a mapped class an component?

Referencing the following figure:

http://www.dafunks.com/hibernate/many-t ... oblems.jpg

I have:
0. component relationship from the Preferences class to the WarningPreferences class
1. one-to-many relationship from the WarningPreferences class to the WarnedUsers class
2. many-to-one relationship from the WarnedUsers class to the WarningPreferences class
3. many-to-one relationship from the WarnedUsers class to the Users class

But at runtime, I get an error about WarningPreferences being an unmapped class. Any suggestions as what to do in this scenario?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 31, 2006 12:22 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
No, that's not possible if you plan on sharing instances (if you want pref.getWarningPreferences() to return the same as pref.getWarnedUsers().iterator().next().getWarningPreferences(), assuming that there's only one WarningPreference in your system). If you want the objects to be properly cached and resued, then you must map the class.

If you don't care (e.g. WarningPreferences is a read-only class) then you could map the component wherever it's needed. But that's not exactly good code resue :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 31, 2006 2:18 pm 
Newbie

Joined: Mon Nov 21, 2005 1:48 pm
Posts: 17
According to: http://www.hibernate.org/hib_docs/refer ... nents.html

The properties of a component may be of any Hibernate type (collections, many-to-one associations, other components, etc). Nested components should not be considered an exotic usage. Hibernate is intended to support a very fine-grained object model.

Is this not the case?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 02, 2006 6:11 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
But mapping the class doesn't change the supported granularity.

The only problem with your mapping is that somewhere, you've told hibernate to load an instance of mapped class WarningPreferences, but you haven't actually mapped the class. A component is inherently unreferencable: it can be accessed only from the mapping that it's defined in. If you map it seperately, you can then reference it from anywhere.

It's like anonymous java classes: anything can call a method in an object of an anonymous class, but only one thing can create that object in the first place.


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