-->
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: How to map a <map> where element is a <set> of e
PostPosted: Tue Nov 13, 2007 6:55 pm 
Newbie

Joined: Wed Jul 27, 2005 3:44 pm
Posts: 12
Location: Los Angeles, CA
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0.5

Mapping documents:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.business.sem" default-cascade="save-update" default-lazy="true">
<class name="VendorAccount" lazy="true" select-before-update="false" table="VendorAccount">
<meta attribute="implements">com.business.sem.IEntityState</meta>
<meta attribute="implements">com.business.sem.ISecurity</meta>
<id name="id" type="java.lang.Long" column="id">
<meta attribute="use-in-tostring">true</meta>
<generator class="identity" />
</id>
<property name="name" column="name" length="50" type="java.lang.String" not-null="true">
<meta attribute="use-in-tostring">true</meta>
<meta attribute="field-description">Name of the account</meta>
</property>
<one-to-one name="settings" class="VendorAccountSettings"
cascade="save-update"
constrained="false"
outer-join="true"
lazy="false"
fetch="join" />

<map name="biddingSchedule" outer-join="true" fetch="select" table="BiddingSchedule" lazy="true">
<key column="accountId" not-null="true" unique="false" />
<map-key-many-to-many class="com.business.sem.DistributionType" column="distributionType" />
<one-to-many class="BiddingSchedule" />
</map>

<map name="biddingExceptions" inverse="true" outer-join="true" fetch="select" order-by="exceptionDate desc" table="BiddingException" lazy="true">
<key column="accountId" not-null="true" unique="false" />
<map-key-many-to-many class="com.business.sem.DistributionType" column="distributionType" />
<one-to-many class="BiddingException" />
</map>

<many-to-one name="type" class="AccountType" column="accountType" fetch="select" cascade="none" not-null="true">
<meta attribute="field-description">Type of this VendorAccount</meta>
</many-to-one>

<property name="lastUpdate" column="lastUpdate" type="java.sql.Timestamp" not-null="false" update="false" insert="false" />

<many-to-one name="status" class="Status" column="status" fetch="select" cascade="none" not-null="true">
<meta attribute="field-description">Status of this VendorAccount</meta>
</many-to-one>
</class>
</hibernate-mapping>

Name and version of the database you are using:
SQLServer 2000

BiddingException table is (pseudo-sql):
id INT PRIMARY KEY
accountId BIGINT FOREIGN KEY FOR VendorAccount.id
distributionType CHAR(1) FOREIGN KEY FOR DistributionType.code
exceptionDate DATETIME;

As you can see, VendorAccount can have multiple BiddingExceptions (1:M).
How can I map this relationship? I would like to be able to use it like this:

Code:
Set<java.sql.Date> dateSet = vendorAccount.getBiddingSchedule().get (SEARCH_MARKETING_TYPE)


The <map> definition in bold above maps just single date per each value of <map-key-many-to-many> and the spec doesn't allow to specify a <set> inside the <map> definition.

Is there a better way to map it? I think I could do it using subclasses: then I could use map key as a discriminator and get all ContentBiddingExceptions and SearchMarketingBiddingExceptions, but I'd prefer to just have a map keyed by DistributionType and containing Lists of dates, or list of BiddingExceptions.

_________________
Maxim Senin
Custom Software Development for the Enterprise
http://www.supremistic.com/


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.