-->
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: filter or query by subclass and by filter
PostPosted: Mon Sep 28, 2009 11:10 am 
Newbie

Joined: Mon Sep 28, 2009 11:03 am
Posts: 2
Hi, i was wondering if it was possible/how to. restrict the results of a set, by both a subclass, and or daterange.
currently i'm using a filter for the daterange, but if it is a recurring event, I want to ignore the filter.

<class name="Calendar" table="calendar">
<id name="id" column="id">
<generator class="identity"/>
</id>
<property name="name" column="name"/>
<many-to-one name="person" class="Person" column="person_id"/>
<set name="events" table="calendar_has_event" lazy="false">

<key column="calendar_id"/>
<many-to-many column="event_id" class="Event">
<filter name="dateConstraint" condition="begin_dt BETWEEN :calStartDate and :calEndDate"/>

</many-to-many>

</set>
</class>


<joined-subclass name="RecurringEvent" extends="Event" table="recurring-event">
....
</joined-subclass>

<class name="Event" table="event">
<id name="id" column="id">
<generator class="identity"/>
</id>
<property name="name" column="name"/>
<property name="beginDate" column="begin_dt"/>
<property name="endDate" column="end_dt"/>
.....

</class>


Top
 Profile  
 
 Post subject: Re: filter or query by subclass and by filter
PostPosted: Mon Sep 28, 2009 3:05 pm 
Senior
Senior

Joined: Mon Jul 07, 2008 4:35 pm
Posts: 141
Location: Berlin
Hi nugaluga,

how about issuing a query on the associated entities?

If you do a proper inheritance mapping a polymorphic collection is no problem for Hibernate and you can query by any mapped sub-type.

CU
Froestel

_________________
Have you tried turning it off and on again? [Roy]


Top
 Profile  
 
 Post subject: Re: filter or query by subclass and by filter
PostPosted: Thu Oct 08, 2009 4:10 pm 
Newbie

Joined: Mon Sep 28, 2009 11:03 am
Posts: 2
can you explain what you mean by associated entities?
do you mean

If I query Event.class, i want to filter the dates on that the event
but if the Event.class is an instance of Recurring Events, which extends events, than i want it to return the recurring event as well.
I can do this in two queries, but i'd rather do it in one.

thank you


Top
 Profile  
 
 Post subject: Re: filter or query by subclass and by filter
PostPosted: Sat Oct 10, 2009 4:06 am 
Senior
Senior

Joined: Mon Jul 07, 2008 4:35 pm
Posts: 141
Location: Berlin
Hi nugaluga,

nugaluga wrote:
can you explain what you mean by associated entities?

An associated entity is an entity to which there is a relation (s.c., association). In your mappings, i.e., the Person entity is an associated entity of the Calendar entity. Read this: Association Mappings

nugaluga wrote:
If I query Event.class, i want to filter the dates on that the event
but if the Event.class is an instance of Recurring Events, which extends events, than i want it to return the recurring event as well.
I can do this in two queries, but i'd rather do it in one.

You can do that, Hibernate supports polymorphism. Consult the Hibernate docs on Inheritance mapping. If you use implicit polymorphism querying the parent entity will also retrieve the children.

CU
Froestel

_________________
Have you tried turning it off and on again? [Roy]


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.