-->
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 can I add dynamic fields to entities
PostPosted: Fri Feb 12, 2010 5:46 am 
Newbie

Joined: Sat Jan 24, 2009 7:12 am
Posts: 9
Hello.
I'm gonna write an internet shop, and currently i'm thinking about its Model layer.
If it's gonna be an abstract Entity, then users should be able to add arbitrary types of Entities to the shop.
For example, they might want to add a Vehicle, or a Flower, or a Pig.
Each such entity has different properties, for example a Vehicle has its speed, a Flower has its sort, and a Pig has its farm, where it has been breeded.

So, how can I implement all these infinite properties in Hibernate, so that it be fast and lightweight?

I could, for example, create a column named "additional properties" with some sort of XML such as:

Code:
<properties>
<property name="speed" value="10kmph"/>
<property name="age" value="10"/>
<property name="flavour" value="strawberry"/>
</properties>


But how would I then be able to get all the Juices with "strawberry" flavour?
There would be no query such as "from Entity entity where additionalProperties.flavour = "strawberry", would it?

What solution can you propose me to address this cusiom entity issue?

*As you've already understood, I'm unable to create the Juice class and map it in Hibernate - that's the user who creates new types of Entities.


Top
 Profile  
 
 Post subject: Re: How can I add dynamic fields to entities
PostPosted: Mon Feb 15, 2010 5:01 am 
Newbie

Joined: Sat Jan 24, 2009 7:12 am
Posts: 9
maybe you give me any hints on this topic?
anyone?


Top
 Profile  
 
 Post subject: Re: How can I add dynamic fields to entities
PostPosted: Mon Feb 15, 2010 5:31 am 
Newbie

Joined: Sun Feb 14, 2010 8:08 am
Posts: 12
This one is rather design decision you are asking about rather than hibernate query. Anyways I would rather go with having an entity called attribute type and attribute map, attribute type contains all the types we need and mapper contains the properties of that attribute. should be done with 2 table.


Top
 Profile  
 
 Post subject: Re: How can I add dynamic fields to entities
PostPosted: Mon Feb 15, 2010 5:53 am 
Newbie

Joined: Sat Jan 24, 2009 7:12 am
Posts: 9
mpujari80 wrote:
This one is rather design decision you are asking about rather than hibernate query. Anyways I would rather go with having an entity called attribute type and attribute map, attribute type contains all the types we need and mapper contains the properties of that attribute. should be done with 2 table.


You mean this?

Code:
class Attribute
{
   Long id;
   String name;
}


Code:
class AttributeMap
{
   Attribute attribute;
   Entity entity;
   String value;
}


That's an interesting solution...
It projects nicely onto an HQL query:

Code:
select entity from AttributeMap attributeMap inner join attributeMap.entity where attributeMap.attribute.name = "religion" and attributeMap.value = "slavic paganism"


Did i get you correct?


Top
 Profile  
 
 Post subject: Re: How can I add dynamic fields to entities
PostPosted: Mon Feb 15, 2010 6:38 am 
Newbie

Joined: Sun Feb 14, 2010 8:08 am
Posts: 12
Yes you got me correctly, and I think we can hence it more ;)


Top
 Profile  
 
 Post subject: Re: How can I add dynamic fields to entities
PostPosted: Mon Feb 15, 2010 6:39 am 
Newbie

Joined: Sat Jan 24, 2009 7:12 am
Posts: 9
thanks : )


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.