-->
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: Having trouble with maps
PostPosted: Tue Sep 30, 2003 7:32 pm 
Newbie

Joined: Tue Sep 30, 2003 7:10 pm
Posts: 10
Hello,
I'm trying to get a simple mapping going where I have an object that contains a map that has a particular object as key and another as value.


basically:

ResourceBundle r;
Map m = r.getResources();
Locale l = new Locale("", "");

ResourceBundleEntries e = (ResourceBundleEntries) m.getl(l);
String blah = (String) e.getResources().get("some_key");
(I know these names do not make a whole lot of sense...)

Anyway, I get the error listed below with my mapping.

Anyone know what I might be doing wrong? Thanks...

Caused by: net.sf.hibernate.PropertyNotFoundException: Could not find a getter for resources in class com.foo.ResourceBundleEntries

<class name="com.foo.Locale" table="locale">
<id name="id" type="string" unsaved-value="null" >
<column name="id" sql-type="char(32)" not-null="true"/>
<generator class="uuid.hex"/>
</id>

<property name="language" type="string" not-null="true"/>
<property name="country" type="string" not-null="true"/>

</class>

<class name="com.foo.ResourceBundleEntries" table="resource_bundle_entries">
<id name="id" type="string" unsaved-value="null" >
<column name="id" sql-type="char(32)" not-null="true"/>
<generator class="uuid.hex"/>
</id>

<map name="resources" lazy="true" >
<key column="id"/>
<index column="key" type="string"/>
<element column="value" type="string"/>
</map>

<many-to-one name="locale" class="com.foo.Locale"/>

</class>

<class name="com.foo.ResourceBundle" table="resource_bundle">
<id name="id" type="string" unsaved-value="null" >
<column name="id" sql-type="char(32)" not-null="true"/>
<generator class="uuid.hex"/>
</id>
<property name="name" type="string" not-null="true"/>

<map name="resources" lazy="true">
<key column="id"/>
<composite-index class="com.foo.Locale">
<key-property name="language" type="string"/>
<key-property name="country" type="string"/>
</composite-index>

<composite-element class="com.foo.ResourceBundleEntries">

</composite-element>
</map>

</class>


Top
 Profile  
 
 Post subject: sorry, this may be more readable
PostPosted: Tue Sep 30, 2003 7:53 pm 
Newbie

Joined: Tue Sep 30, 2003 7:10 pm
Posts: 10
Sorry, I didn't put the code tags around my code. This may be more readable


Code:
    <class name="com.foo.Locale" table="locale">
        <id name="id" type="string" unsaved-value="null" >
            <column name="id" sql-type="char(32)" not-null="true"/>
            <generator class="uuid.hex"/>
        </id>

        <property name="language" type="string" not-null="true"/>
        <property name="country" type="string" not-null="true"/>

    </class>

    <class name="com.foo.ResourceBundleEntries" table="resource_bundle_entries">
        <id name="id" type="string" unsaved-value="null" >
            <column name="id" sql-type="char(32)" not-null="true"/>
            <generator class="uuid.hex"/>
        </id>

        <map name="resources" lazy="true" >
            <key column="id"/>
            <index column="key" type="string"/>
            <element column="value" type="string"/>
        </map>

        <many-to-one name="locale" class="com.foo.Locale"/>

     </class>

    <class name="com.foo.ResourceBundle" table="resource_bundle">
        <id name="id" type="string" unsaved-value="null" >
            <column name="id" sql-type="char(32)" not-null="true"/>
            <generator class="uuid.hex"/>
        </id>
        <property name="name"  type="string" not-null="true"/>

        <map name="resources" lazy="true">
            <key column="id"/>
            <composite-index class="com.foo.Locale">
                <key-property name="language" type="string"/>
                <key-property name="country" type="string"/>
            </composite-index>

            <composite-element class="com.foo.ResourceBundleEntries">

            </composite-element>
        </map>

    </class>


Top
 Profile  
 
 Post subject: Do you have public getter/setter for "resources"?
PostPosted: Tue Sep 30, 2003 8:05 pm 
Senior
Senior

Joined: Sun Aug 31, 2003 3:14 pm
Posts: 151
Location: Earth (at the moment)
What does your class look like?

Do you have the following in it?
Code:
public Map getResources() { /* ... */ }


Top
 Profile  
 
 Post subject: Re: Do you have public getter/setter for "resources&quo
PostPosted: Tue Sep 30, 2003 8:15 pm 
Newbie

Joined: Tue Sep 30, 2003 7:10 pm
Posts: 10
DavidNDuffy wrote:
What does your class look like?

Do you have the following in it?
Code:
public Map getResources() { /* ... */ }


hibernate should be generating the java code for com.foo.ResourceBundleEntries, so I wouldn't need to...

Also, interestingly, if I change

Code:
        <map name="resources" lazy="true">
            <key column="id"/>
            <composite-index class="com.foo.Locale">
                <key-property name="language" type="string"/>
                <key-property name="country" type="string"/>
            </composite-index>

            <composite-element class="com.foo.ResourceBundleEntries">

            </composite-element>
        </map>



to



Code:
        <map name="resources" lazy="true">
            <key column="id"/>
            <composite-index class="com.foo.Locale">
                <key-property name="language" type="string"/>
                <key-property name="country" type="string"/>
            </composite-index>

            <element type="string"/>
        </map>



It works, but obviously not what I want.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 01, 2003 5:03 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
You need some <property> tags inside the <composite-element> declaration!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 01, 2003 2:12 pm 
Newbie

Joined: Tue Sep 30, 2003 7:10 pm
Posts: 10
gavin wrote:
You need some <property> tags inside the <composite-element> declaration!


I tried that and get the same error. What I don't understand is why compisite-element cares about a getter for the map in the other class.


Top
 Profile  
 
 Post subject: Simpler example works fine
PostPosted: Wed Oct 01, 2003 4:09 pm 
Newbie

Joined: Tue Sep 30, 2003 7:10 pm
Posts: 10
I created a much simpler example which works fine. I do not see why I get errors on my original one above and this one works fine...

e.g.
KeyObject key = ...
MapClass mc = ...
Map m = mc.getKvMapping();

ValueObject vo = (ValueObject) m.get(key);



Code:
    <class name="KeyObject" table="ko">
        <id name="id" type="string" unsaved-value="null" >
            <column name="id" sql-type="char(32)" not-null="true"/>
            <generator class="uuid.hex"/>
        </id>
        <property name="name" type="string" not-null="true"/>
        <property name="someField" type="string" not-null="true"/>

    </class>

    <class name="ValueObject" table="vo">
        <id name="id" type="string" unsaved-value="null" >
            <column name="id" sql-type="char(32)" not-null="true"/>
            <generator class="uuid.hex"/>
        </id>
        <property name="name" type="string" not-null="true"/>
        <property name="someOtherField" type="string" not-null="true"/>
    </class>

    <class name="MapClass" table="mc">
        <id name="id" type="string" unsaved-value="null" >
            <column name="id" sql-type="char(32)" not-null="true"/>
            <generator class="uuid.hex"/>
        </id>
        <map name="kvMapping" lazy="true" >
            <key column="id"/>
            <composite-index class="KeyObject" >
                <key-property name="name"/>
                <key-property name="someField"/>
            </composite-index>
            <composite-element class="ValueObject" />

        </map>

        <property name="name" type="string" not-null="true"/>
        <property name="someOtherField" type="string" not-null="true"/>
    </class>


Top
 Profile  
 
 Post subject: Errors in Maps of objects with maps
PostPosted: Wed Oct 01, 2003 5:42 pm 
Newbie

Joined: Tue Sep 30, 2003 7:10 pm
Posts: 10
I'm refining down the trouble I mentioned in another thread.

The first mapping below works fine. The second mapping fails. Note the only different is that "ValueObject" has a simple map added to it. Can anyone explain why this fails?

Quote:
Schema text failed: Problem trying to set property
type by reflection: Could not find a getter for stuff in class ValueObject


This mapping works fine:
Code:

    <class name="KeyObject" table="ko">
        <id name="id" type="string" unsaved-value="null" >
            <column name="id" sql-type="char(32)" not-null="true"/>
            <generator class="uuid.hex"/>
        </id>
        <property name="name" type="string" not-null="true"/>
        <property name="someField" type="string" not-null="true"/>

    </class>

    <class name="ValueObject" table="vo">
        <id name="id" type="string" unsaved-value="null" >
            <column name="id" sql-type="char(32)" not-null="true"/>
            <generator class="uuid.hex"/>
        </id>
        <property name="name" type="string" not-null="true"/>
        <property name="someOtherField" type="string" not-null="true"/>
    </class>

    <class name="MapClass" table="mc">
        <id name="id" type="string" unsaved-value="null" >
            <column name="id" sql-type="char(32)" not-null="true"/>
            <generator class="uuid.hex"/>
        </id>
        <map name="kvMapping" lazy="true" >
            <key column="id"/>
            <composite-index class="KeyObject" >
                <key-property name="name"/>
                <key-property name="someField"/>
            </composite-index>
            <composite-element class="ValueObject" />

        </map>

        <property name="name" type="string" not-null="true"/>
        <property name="someOtherField" type="string" not-null="true"/>
    </class>


2nd mapping, fails:

Code:
    <class name="KeyObject" table="ko">
        <id name="id" type="string" unsaved-value="null" >
            <column name="id" sql-type="char(32)" not-null="true"/>
            <generator class="uuid.hex"/>
        </id>
        <property name="name" type="string" not-null="true"/>
        <property name="someField" type="string" not-null="true"/>

    </class>

    <class name="ValueObject" table="vo">
        <id name="id" type="string" unsaved-value="null" >
            <column name="id" sql-type="char(32)" not-null="true"/>
            <generator class="uuid.hex"/>
        </id>
        <property name="name" type="string" not-null="true"/>
        <property name="someOtherField" type="string" not-null="true"/>
        <map name="stuff" lazy="true" >
            <key column="id"/>
            <index column="key" type="string"/>
            <element column="value" type="string"/>
        </map>
    </class>

    <class name="MapClass" table="mc">
        <id name="id" type="string" unsaved-value="null" >
            <column name="id" sql-type="char(32)" not-null="true"/>
            <generator class="uuid.hex"/>
        </id>
        <map name="kvMapping" lazy="true" >
            <key column="id"/>
            <composite-index class="KeyObject" >
                <key-property name="name"/>
                <key-property name="someField"/>
            </composite-index>
            <composite-element class="ValueObject" />

        </map>

        <property name="name" type="string" not-null="true"/>
        <property name="someOtherField" type="string" not-null="true"/>
    </class>
Quote:


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.