-->
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: Multiple assocaition issues
PostPosted: Mon Oct 27, 2003 8:28 pm 
Newbie

Joined: Mon Oct 27, 2003 8:15 pm
Posts: 10
Location: Birmingham, AL
I have a situation that I need mapped but I'm unclear as to how to proceed forward, since this is my first real exposure to Hibernate.

I have a table containing Help topics.
There are approximately 30+ other tables within my dataset that reference Help topics. Each one has an id that points back to some instance of Help.
I do not have an individual help table for each of the other tables, so it's sort of a one-to-many-different-tables association. In this, help topic id=1 might be associated with 20 different tables, all of which have a 0..1 association to Help via a helpID.

So my question is how to proceed forward. This is not a typical collections-based association, since it's not just one element associated with many elements of a single other table.

Do I need to acquire my help topics separately? That'd probably be the simplest means now. I'd just like to be able to do a "getHelp" from a persisited class and get the help information, associated with it, if any.

Suggestions would be appreciated.
Thanks,
M


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 27, 2003 8:38 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I don't really follow what is difficult about this. Don't Foo and Bar just have a getHelp() property? ie. each just has a <many-to-one> to Help.


Perhaps I misunderstoof, and it is a case for <any> or <many-to-any>.


Top
 Profile  
 
 Post subject: Many-to-one
PostPosted: Wed Oct 29, 2003 12:15 pm 
Newbie

Joined: Mon Oct 27, 2003 8:15 pm
Posts: 10
Location: Birmingham, AL
You didn't misunderstand. I mis-stated the problem. And there shouldn't be anything difficult. I'm just not getting it. :(

The issue was that I can't retrieve the dependent associate objects, and I was wondering if I was forced to place a one-to-many on the primary object mappings and a many-to-one on the subordinate. I haven't seen anything stated explicitly like that, but all the documentation is starting to swim together before my eyes. :)


As an example, of which there are many like it, I provide the mapping for Catalog. Catalog has a field "help" that points to a primary key value in Help (helpID) that I wish to use to associate Help values with Catalogs.

Catalog mapping has a many to one
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
    <class name="com.sbf.hibertest.Catalog" table="catalog" dynamic-update="false" dynamic-insert="false" >
        <id name="id" column="ID" type="java.lang.Long" length="10" unsaved-value="null" ><generator class="native"> </generator></id>
        <property name="basic_price" type="java.math.BigDecimal" update="true" insert="true" column="basic_price"   not-null="false" unique="false" />
        <property name="dateEnd" type="java.util.Date" update="true" insert="true" column="DateEnd" not-null="false" unique="false" />
        <property name="sku" type="long" update="true" insert="true" column="Sku" not-null="false" unique="false" />
        <property name="dateStart" type="java.util.Date" update="true" insert="true" column="DateStart" not-null="false" unique="false" />

        <many-to-one name="help" class="com.sbf.hibertest.Help" cascade="none" outer-join="auto" update="true" insert="true" column="help" />

    </class>
</hibernate-mapping>

and accessors/mutators for Help in Catalog.java

Code:
   public Help getHelp() {
      return help;
   }
   public void setHelp(Help help) {
      this.help = help;
   }


Help is mapped as

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
    <class name="com.sbf.hibertest.Help" table="help" dynamic-update="false" dynamic-insert="false" >
        <id name="helpID" column="helpID" type="java.lang.Long" length="10" unsaved-value="null" ><generator class="native"> </generator></id>
        <property name="helpDescr" type="java.lang.String" update="true" insert="true" column="helpDescr" not-null="false" unique="false" />
        <property name="helpLongDescr" type="java.lang.String" update="true" insert="true" column="helpLongDescr" not-null="false" unique="false" />
    </class>
</hibernate-mapping>



The Help file has no mapping of one-to-many. This is where I'm confused. There's a ton of documentation re: Collections mapping and the associated one-to-many, but I can't seem to generate a query that doesn't give me a "Can't deserialize a serializable property" error on this simple many to one association.

Could I get some assistance on what a query string that would retreive all of Catalog and its associated help would be like? I know this is easy and I'm just being obtuse, but I've been trying on and off for a few days. Much of that was spent configuring ant, eclipse, and Xdoclet to work and produce the mappings, etc that I'm interested in, but I've spent a bit of time with this query and still can't get it right.
Currently, I'm using the following:

Code:
select cat from Catalog cat, Help help left outer join cat.help as help


I assume that I am failing on the join, which I assume produces the "Can't deserialize blah" exception.

Or am I completely missing the boat.


Top
 Profile  
 
 Post subject: The boat was missed.
PostPosted: Wed Oct 29, 2003 12:43 pm 
Newbie

Joined: Mon Oct 27, 2003 8:15 pm
Posts: 10
Location: Birmingham, AL
I solved my problem.

I had managed to identify my beans as Serializable by inheritance of an interface. It works without flaw now that the classes themselves aren't Serializable.

I'm going to go and turn in my keyboard now. I want a push-broom instead.


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.