-->
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.  [ 6 posts ] 
Author Message
 Post subject: How to map a HashMap containing a List
PostPosted: Thu Sep 27, 2007 8:07 am 
Newbie

Joined: Fri Sep 29, 2006 10:52 am
Posts: 6
Hibernate Version : 3.1.3

I am looking for a way to map HashMap<A, List<B>> as a property. The classes looks something like:

class A {
}

class B {
...
private C ref;
private A keyProperty;
...
}

class C {
...
private HashMap<A, List<B>> map;
...
}

Since the relationship in C's mapping file is, inverse="true", linking tables are not an option. Unfortunately I have not found a way to do this without linking tables, which is weird since all the info needed to be able to do this is already in B's db table. The table has C as a foreign key on as it as well as A.

I looked at the formulate option but don't know how to correlate the key property (keyProperty) in the formula. Is it maybe possible?

C does not cascade any changes nor is it responsible for maintaining the relationship.

Any suggestions will be appreciated.


Top
 Profile  
 
 Post subject: More Information Required
PostPosted: Fri Sep 28, 2007 5:52 am 
Newbie

Joined: Sun Oct 16, 2005 8:52 am
Posts: 4
hello driftwood,

could you please post some more information about your problem, so that we can better understand your problem

e.g. mapping documents, source code, test cases, etc.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 28, 2007 6:33 am 
Newbie

Joined: Fri Sep 29, 2006 10:52 am
Posts: 6
hello paran0rmal,

The mappings looks as follows:
Code:
<hibernate-mapping schema="generalledger">
  <class name="Account" table="Account" dynamic-insert="true" dynamic-update="true">
    <bag name="credits" inverse="true" access="field" where="type='C'">
      <key column="account"/>
      <one-to-many class="CreditEntry"/>
    </bag>

    <bag name="debits" inverse="true" access="field" where="type='D'">
      <key column="account"/>
      <one-to-many class="DebitEntry" />
    </bag>
  </class>
</hibernate-mapping>

<hibernate-mapping schema="generalledger">
  <class name="AccountEntry" table="accountentry" dynamic-insert="true" dynamic-update="true">
    <discriminator column="type" type="string"/>

    <many-to-one name="period" cascade="none"/>
    <many-to-one name="account" class="Account" column="account"
                 cascade="none" not-null="true"/>

    <subclass name="net.tradestream.generalledger.domain.gl.CreditEntry" discriminator-value="C">
    </subclass>

    <subclass name="net.tradestream.generalledger.domain.gl.DebitEntry" discriminator-value="D">
    </subclass>
  </class>
</hibernate-mapping>

<hibernate-mapping schema="generalledger">
  <class name="Period" table="Period" dynamic-insert="true" dynamic-update="true">
    <property name="sequence" column="sequence" type="long"/>
  </class>
</hibernate-mapping>

<hibernate-mapping schema="generalledger">

  <class name="AccountTransaction" table="AccountTransaction" dynamic-insert="true" dynamic-update="true" >
    <many-to-one name="period" column="period" cascade="none" not-null="true"/>

    <bag name="entries" access="field" cascade="all-delete-orphan" inverse="true">
      <key column="accountTransaction"/>
      <one-to-many class="AccountEntry"/>
    </bag>

  </class>
</hibernate-mapping>


I am trying to change the account to use a HashMap for the debits and credits and not as List. The HashMap should be keyed by the period in which the entry was created.

The Transaction is created and the entries are added to it and the Account. Only when the Transaction is persisted are the AccountEntries persisted.

I have only been able to map HashMap<Period, CreditEntry> and HashMap<Period, DebitEntry>, but obviously I need a list.

I hope that makes it a bit clearer, if not please let me know and I will post more information.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 28, 2007 8:01 am 
Newbie

Joined: Sun Oct 16, 2005 8:52 am
Posts: 4
Can you please give us an idea of the flow of you code, for example session management etc inside your program


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 28, 2007 9:04 am 
Newbie

Joined: Fri Sep 29, 2006 10:52 am
Posts: 6
Account is read up from the session.
A new Transaction is created and new entries are added to it. The entries are then added to the Account and the account is set on the entries.

Transaction is then explicitly persisted as the session does not know about it or the entries.

This all happens in a single session.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 28, 2007 9:34 am 
Newbie

Joined: Sun Oct 16, 2005 8:52 am
Posts: 4
I'm not sure if I understand your program. Can you please provide more information?


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