-->
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: Manipulating Metadata at Runtime
PostPosted: Wed Apr 13, 2005 2:20 pm 
Beginner
Beginner

Joined: Wed Apr 13, 2005 2:03 pm
Posts: 34
Hi folks,

I hope somebody can help me with this. Basically, I have a user requirement that they be able to "add" fields to my objects after the product ships. Historically I've solved this problem with metadata driven systems where the user could just modify the metadata and their meta-object would change.

Recently though I've fallen in love with hibernate (it solves all the ugly problems that usually eat months of development time). So I'd like to use hibernate to achive my goals. My approach to date was to use POJOs and hibernate as my "core" datatypes and then let my users extend my POJOs via metadata. I then planned to "glue" the user extensions onto my objects by using hibernate's metadata manipulation capabilities.

However, the only reference material I've been able to find on that capability references hiberate 2.1, and I'm on hibernate 3.0. Some of the methods have been depricated since then and I can't figure out how to use the new ones.

Speficially, I'm looking at this code which I more or less cribbed from "Hibernate in Action".

Configuration cfg = HibHelper.getConfiguration();
PersistentClass userMapping;
userMapping = cfg.getClassMapping(User.class.getName());
Column c = new Column();
c.setName("pet");
c.setNullable(true);
c.setUnique(false);
** c.setType(Hibernate.STRING); // depricated in 3.0?

userMapping.getTable().addColumn(c);
SimpleValue v = new SimpleValue();
v.setTable(userMapping.getTable());
v.addColumn(c);
** //v.setType(Hibernate.STRING); depreicated in 3.0?
v.setTypeName(Hibernate.STRING.getName());

Property p = new Property();
p.setValue(v);
p.setName("Pet");
userMapping.addProperty(p);

Specifc questions:

Above, I marked a line of code with a ** because that particular method appears depricated in 3.0. There's a new Column.setTypeIndex() method that takes an int as its arg, but I'm not sure what int cooresponds to each Hibernate type. Can anyone help me on this one?

Secondly and probably more awkwardly, I'm a bit stumped on how to *use* my new property in code. If I want to create a user object with a pet named "fred", how do I tell hibernate that the user's pet is named fred?

If I instantiate a "core" User e.g. User u = new User(), it won't have a property named "pet".

If I proxy the User and add a pet method to it, will hibernate still be able to work with it? Or will I just totally narf Hibernates own reflection code if I pass it a dynamic proxy instead of a POJO?

Alternately, is there some other approach I should be taking here? Reading through the doc it sure looks like other people have solved this problem, but I'm just not seeing my way through to the end yet.

Any help or suggestions would be appeciatded.


Top
 Profile  
 
 Post subject: Adding metadata at run time
PostPosted: Mon Aug 29, 2005 7:34 pm 
Newbie

Joined: Thu May 12, 2005 3:51 pm
Posts: 7
Did you ever figure out how to add to the meta data at run time?


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.