-->
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.  [ 9 posts ] 
Author Message
 Post subject: mapping one generic class to a table dynamically
PostPosted: Wed Feb 04, 2004 2:07 pm 
Newbie

Joined: Wed Feb 04, 2004 1:57 pm
Posts: 7
Hello,

I would like to map a "meta-class" to a table depending in the values from the meta- class.

The usual way to map classes to tables is that you have a class named "Car" and a table named "TABLE_CAR" and you do the mapping in hqm.

I want to map a class named "GenericClass"
to a table named "CAR" if the property of the instance of the GenericClass class is typeOfClass is "car" or
it the property typeOfClass is "mouse" i want to map that generic class
to the table "MOUSE".

There is a way for using hibernate with that type of "dynamic" mapping depending of the state of a an object??


Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2004 2:09 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Most likely there is no easy way, mappings are fixed once the SessionFactory is built. Refer to http://www.hibernate.org/171.html


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2004 3:42 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
1. inheritance does not solve your pb ?
GenericClass <- Mouse
GenericClass <- Cat

2. What's the purpose of having generic properties on several tables ?

3. Try using partitioned tables in your DB

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2004 5:00 pm 
Newbie

Joined: Wed Feb 04, 2004 1:57 pm
Posts: 7
Hello,

No, there is no inheritance in my classes.

I only have ONE class. This class is a MetaEntity that has attributes
and list of other MetaEntitys.

With that class i want to create Objects without methods but with data.

I want that the user has the possibility to create his own classes only for data.

The definition of the classes will be defined in xml or other mechanism.

With that definition i know what atributes an Entity object has and what other object Entitys has.

Then comes hibernate, i want to persist and recover that data in/from the database.

Example:

I have an office withe Salesman

I need two objects SalesOffice and Salesman

I would have a definition (in xml for example) with the Salesman class:

class_type Salesman
attribute name with type String
attribute age with type Integer

class_type SalesOffice
attribute company_name with type String
attribute address_name withe type String
attribute address_city with type String
attribute listOfObjects of type Salesman

With that definition i will have instances of that definition that will be Entities (a definition example in xml):

<Entity type = "SalesOffice">
<Property name="company_name" value="IBM">
<Property name="adress_name" value="Road High 23">
<List type="Salesman">
<Entity type="Salesman">
<Property name="name" value="Peter"/>
<Property name="age" value="23"/>
<Entity/>
<Entity type="Salesman">
<Property name="name" value="Bob"/>
<Property name="age" value="43"/>
<Entity/>
</List>
</Entity>


Well i want to persist this data to the database, but i want to persist it in
diferent tables, and not in a single table.

The objects of type SalesOffice in the table SALES_OFFICES and
the objects of type Salesman in the table SALES_MAN

For what i have seen there is a one to one relationship betwen a class and a table.

Thank you for reading me.


Top
 Profile  
 
 Post subject: Hibernate and dynamic models
PostPosted: Wed Feb 04, 2004 7:31 pm 
Newbie

Joined: Wed Feb 04, 2004 1:57 pm
Posts: 7
Hello Again,

Do you know if the tag <dynamic-class> described in the
article http://www.hibernate.org/171.html is destinated to resolve the issue?

Thank you.


Top
 Profile  
 
 Post subject: Re: Hibernate and dynamic models
PostPosted: Wed Feb 04, 2004 8:15 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
emartin wrote:
Hello Again,

Do you know if the tag <dynamic-class> described in the
article http://www.hibernate.org/171.html is destinated to resolve the issue?

Thank you.


Except for the casting by property, maybe. I've not think enough of this feature yet.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 05, 2004 5:26 am 
Newbie

Joined: Sat Jan 10, 2004 8:02 am
Posts: 15
Location: Munich, Germany
I have to solve exactly the same problem in the insurance line of business:

Actuaries invent new type of treaties which must be administered
in a DB.

Every type of treaty is a new class (or an extension of an existing class)
with additional attributes and associations.

I create the tables dynamically, no problem.

But I have to use a generic java class in order to avoid the creation
of new java files every day a new type of treaty is invented.

I could also solve this by creating a java source file and compiling it
in the background (or directly create the byte code file via cglib...),
but this is really dirty.

---

I am examining the dynamic-class feature of hibernate v2.2 at the moment and I don't think it solves your problem, because
it seems to create a map instance and I do not know at the
moment how to find out the class name the map instance is representing
(somehow hibernate must know this, otherwise it couldn't update the DB).


---

So please, hibernate team, continue your work to support a generic business class.

In its simpliest form it consist only of the following interface
(implementation left to your imagination ;-):

class GenericBusinessClass {
public String get className();
public Object getPropertyValue( String propertyName );
public void setPropertyValue( String propertyName, Object newValue );
}

A property can be a simple attribute or an association...


Top
 Profile  
 
 Post subject: hibernate 2.2 branch and dynamic-class
PostPosted: Thu Feb 05, 2004 9:52 am 
Newbie

Joined: Wed Feb 04, 2004 1:57 pm
Posts: 7
Hello

I have downloaded the version 2.2 branch that have the
dynamic-class feature.

I tried to test the MapTest TestCase that test the dynamic-class functionality.

The buildSeesionFactory method from Configuration class file, seems
to not be aware of the diferent "behaviour" of the dynamic-class type.

Seems that is trying to get the setter for the id attribute in the Map Interface, but obiously the Map interface doesn


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 05, 2004 9:54 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
2.2 is not even alpha :)

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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