-->
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.  [ 1 post ] 
Author Message
 Post subject: Mapping of entities with <map> usage
PostPosted: Wed Feb 15, 2006 3:23 pm 
Regular
Regular

Joined: Mon Jun 13, 2005 12:21 pm
Posts: 61
Location: Hannover
Hi,

I've got a mapping problem with an AttributeValue Pattern. I want do be my classes to be some kind of dynamic extensible. So I've created an Object AttributeValue which can be added in a collection in each of my business classes.
Each business class contains a map with the related AttributeValues of the object. Now I'm looking for a solution to map this behavior with hibernate. Everything works fine as long as I can set the <index> attribute of my Maps to not-null but when I allow foreign keys with null values my values aren't retrieved from the database (they are stored, I can see them with an manual SQL statement).
I would also be glad if there is some better solution for this problem.

I've used mySQL and HSQLDB but I guess that database doesn't matter.

Thanks a lot
Joerg

Hibernate version: 3.05


Mapping documents:

Code:
<class name="AttributeValueImpl" table="AttributeValue">
        <id name="id" access="org.hibernate.property.DirectPropertyAccessor">
            <generator class="native"/>
        </id>
        <property name="date" type="java.util.Date" column="datevalue" />
        <property name="double" column="doublevalue" type="double"/>
        <property name="integer" column="integervalue" type="integer"/>
        <property name="string" column="stringvalue" type="string"/>
</class>



Code:
  <class name="AddressImpl" table="Address" >
        <id name="id" access="org.hibernate.property.DirectPropertyAccessor">
            <generator class="native"/>
        </id>
        <property name="addressNo" />

        <map name="avMap" lazy="false" access="org.hibernate.property.DirectPropertyAccessor" cascade="all-delete-orphan">
            <key column="ADDRESS_ID"/>
            <index column="addresskey" type="string"/>
            <one-to-many class="de.gish.am.data.AttributeValueImpl"/>
        </map>
       ...
    </class>


Code:
   <class name="AbstractBusinessPartner" table="BusinessPartner">
        <id name="id"
            access="org.hibernate.property.DirectPropertyAccessor">
            <generator class="native" />
        </id>
        <map name="avMap" lazy="false" access="org.hibernate.property.DirectPropertyAccessor" cascade="all-delete-orphan">
            <key column="BUSINESSPARTNER_ID"/>
            <index column="businesspartnerkey" type="string" />
            <one-to-many class="de.gish.am.data.AttributeValueImpl" />
        </map>
       ...
    </class>


Code between sessionFactory.openSession() and session.close():
Code:
        Company comp = BusinessObjectFactory.createCompany();
        AttributeValueImpl av = new AttributeValueImpl();
        av.setString("Sachsen-Anhalt");
        comp.put("Bundesland",av);
        dao.saveObject(comp);
       
        Integer id = comp.getId();
        dao.clearSession();
       
        Company comploaded = (Company)dao.loadByID(Company.class, id.intValue());
        assertNotNull(comploaded);

>>>>    Fails
        assertEquals("Sachsen-Anhalt", comploaded.get("Bundesland"));     


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.