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: How to add mappings/classes dynamically
PostPosted: Thu Apr 26, 2007 10:40 pm 
Newbie

Joined: Tue Jul 18, 2006 1:17 pm
Posts: 8
Good evening,

I'm looking to design an extensible object model on top of hibernate, by this I mean the following:

I have an existing object model mapped with hibernate and POJOs.

I wish to have a number of "empty" colums in the database of various types, and each object in the domain model has a one-to-one to a loosly defined pojo class that is the parent of the dynamic classes, mapped onto the same table as the primary pojo class.

I'll then allow (via groovy) new classes at runtime. I wish to then map properties of these classes to existing columns in the database.

I can then use hql to do reporting, searching, etc against a normalized physical model. The extension classes will also be available to the classloader, such that they'll be visible in jsf el expressions / Freemarker templates etc.

I've spent a bit of time looking at the source for Configuration, Mapping, PersistentClass, Table, etc (org.hibernate.mapping.*), but I'm wondering if anyone has done something similar or has any pointers to ease the pain of doing what I'm working on.

I plan to store these groovy defined classes in the DB (or on the file system) such that at container/configuration reload I'll load the default object model and then modify it with my extensions.

I'm going to keep digging in the source and taking baby steps, but any thoughts or guidance are greatly appreciated.

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 27, 2007 2:27 pm 
Newbie

Joined: Fri Apr 20, 2007 3:46 pm
Posts: 15
I haven't done that so I don't know all the tips/tricks but maybe this will help you out.



Code:
PersistentClass  persistentClass = configuration.getClassMapping(entityName);
Column column = new Column();
column.setName("my_col");
persistencClass.getTable().addColumn ( column );



I am not sure what are all the setters you need to call to add all the objects but I guess you should look at the mapping file and duplicate all the elements and attributes with setters.


Top
 Profile  
 
 Post subject: How do use NHibernate with extensible schema?
PostPosted: Wed Oct 10, 2007 11:29 am 
Newbie

Joined: Wed Oct 10, 2007 11:02 am
Posts: 2
I have the exact same question as stibrian, regarding how to build an extensible database schema using NHibernate.

For each extensible Entity, there are two database tables [Entity] and [Entity]Extension. These two tables are mapped 1-to-1. The first table [Entity] is known at design time, but the second table [Entity]Extension changes during runtime. It is also possible to add a new pair of [Entity] and [Entity]Extension during runtime.

Even though I can provide both the object classes and the hbm mapping files of both [Entity] and [Entity]Extension, the [Entity]Extension's schema will be modified by user during run-time.

How do I adjust NHibernate SessionFactory's class mapping of [Entity]Extension during run-time to reflect new changes?

How do I adjust initialized .NET Assembly Type of [Entity]Extension during run-time to cope with NHibernate SessionFactory?

It can be assumed that only addition of columns, or new types are allowed.

Will the use of multiple session factory help?

Will the use of multiple AppDomain help?


Top
 Profile  
 
 Post subject: How do use NHibernate with extensible schema?
PostPosted: Wed Oct 10, 2007 11:31 am 
Newbie

Joined: Wed Oct 10, 2007 11:02 am
Posts: 2
I have the exact same question as stibrian, regarding how to build an extensible database schema using NHibernate.

For each extensible Entity, there are two database tables [Entity] and [Entity]Extension. These two tables are mapped 1-to-1. The first table [Entity] is known at design time, but the second table [Entity]Extension changes during runtime. It is also possible to add a new pair of [Entity] and [Entity]Extension during runtime.

Even though I can provide both the object classes and the hbm mapping files of both [Entity] and [Entity]Extension, the [Entity]Extension's schema will be modified by user during run-time.

How do I adjust NHibernate SessionFactory's class mapping of [Entity]Extension during run-time to reflect new changes?

How do I adjust initialized .NET Assembly Type of [Entity]Extension during run-time to cope with NHibernate SessionFactory?

It can be assumed that only addition of columns, or new types are allowed.

Will the use of multiple session factory help?

Will the use of multiple AppDomain help?


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.