-->
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.  [ 3 posts ] 
Author Message
 Post subject: A non-collection with a WHERE condition (or equivalent)??
PostPosted: Mon Apr 10, 2006 11:03 am 
Newbie

Joined: Mon Apr 10, 2006 10:33 am
Posts: 7
Location: LA
Hibernate version:3

I've studied up but can't seem to find a way to deal with this (possibly unorthodox) situation:

I have a mySQL database that stores 'text elements' which is to say various and sundry items of text which are related to other entities (a simple example would be model #, headline, multiple bullet copy points etc. for a product)

Anyway, there are multiple text elements (rows of the text table) related to a given product. They are distinguished from one another by a 'type' field in the text table. (So all bullets have type = "bullet" in the table etc. etc.)

THE QUESTION:

I can easily map a collection of bullets, for example, to my Product class using:

Code:
<list name="bullets"
   table="text"
   where="type = 'bullet'">
       ...
</list>


which works quite well.

BUT

How can I do the same thing for a SINGLE value? (How can I do the equivalent of adding a WHERE condition to a normal single property - not a collection?)

as in:
Code:
<property name="modelNumber" where="type = 'modelNumber'"..... />


Which (obviously) won't work, but it illustrates what I'm trying to do.

Is there a way to accomplish this?

EXTRA INFO:
Obviously, a 'list' mapping would be better prepared for possibilities like MULTIPLE 'modelNumber' types that would match the where condition, but I'd like my code to assume that that will never happen with certain types (hopefully by the mapping simply ignoring any extra values) because the UI will never allow the user to create multiples of certain types.

If this situation is referenced in any book or documentation I'm not finding it. I'm thinking there's probably a way to accomplish this but my understanding of Hibernate isn't deep enough to see the solution yet.

Any help or ideas would be greatly appreciated!

Eric


Top
 Profile  
 
 Post subject: 2 c
PostPosted: Mon Apr 10, 2006 3:33 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
A. you can create views in the database which will have appropriate "WHERE" clauses and map entities to the views.
B. Implement the logic in a data access layer.

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 10, 2006 3:37 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
C. Map those elements as entities, class mapping supports "where", so the same class can be mapped multiple times provided that we use different entity names.

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


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