-->
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.  [ 2 posts ] 
Author Message
 Post subject: How could I express this dynamic data model query with JPA?
PostPosted: Wed Dec 08, 2010 6:39 pm 
Beginner
Beginner

Joined: Thu May 26, 2005 10:22 am
Posts: 20
Hi!

I'm developing a JPA based app where I have the following model:

Image

It represents a dynamic data model where I define a Type which is composed of some TypeField. Each TypeField represents a data type definition (contains attributes like name, description, etc.) which can be of any kind (String, Date, Boolean). Then I have some nodes which represent instances of Types. So each Node is composed of NodeFields which can be Strings, Dates, etc. NodeField instances contains the data represented by each TypeField.

I need to query Nodes which match some criterias, where a criteria consist of some constraint applied to each field it is composed of. For example, one query could be "Give me every node which field with ID X of String type contains Y value and which field with ID Z of Date type contains W value.

I've came up with following JPA query:
Code:
SELECT
FROM Node n JOIN n.fields f, StringNodeField sf WHERE sf = f AND f.typeField.id = X AND sf.data LIKE Y AND n IN
( SELECT FROM Node n JOIN n.fields f, DateNodeField sf WHERE sf = f AND f.typeField.id = Z AND sf.data = W )


As you can see, I build multiple partial queries which apply each field constraint and then I merge the results with the IN clause. This works but I wonder If there is a simpler wath to express the query withouth involving a subquery for each field constraint. I need to include the concrete NodeField type (StringNodeField, DateNodeField and so on) because the data is stored in the concrete NodeField and is a different Java type in each case (java.lang.String, java.util.Date, etc.)

Thank you for your help!

Daniel.


Top
 Profile  
 
 Post subject: Re: How could I express this dynamic data model query with JPA?
PostPosted: Fri Dec 10, 2010 3:52 am 
Beginner
Beginner

Joined: Thu May 26, 2005 10:22 am
Posts: 20
Please, any advice?

Thanks.


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