Re: way to specify class's hibernate mapping at runtime?

2 messages Options
Embed this post
Permalink
John Cartwright-8

Re: way to specify class's hibernate mapping at runtime?

Reply Threaded More More options
Print post
Permalink
Thanks Karel, I'm just now getting back to this.  So it looks like I can
construct a DOM  and pass it to the session:

Configuration config = new Configuration();
config.addXML(mappingdocument.asXML());
this.sessionFactory = config.configure().buildSessionFactory();

Does this DOM look just like the .hbm.xml file?  It doesn't look like
the sessionFactory configuration is included here (data from
hibernate.cfg.xml) - how is it added?

On a separate topic - do you have a version of the basic tutorial that
uses annotations rather than the Class hbm.xml file?

Thanks again for your help!

--john



----- Original Message -----
From: Karel Maesen <[hidden email]>
Date: Monday, February 25, 2008 12:05 pm
Subject: Re: [hibernatespatial-users] way to specify class's hibernate
mapping at runtime?

> Hi John,
>
> I've been working on an experimental feature that reads table  
> metadata from the database using JDBC, uses the metadata to
> generate  
> at runtime a bean class file, and a Hibernate mapping from  the
> bean  
> to the table.  If you can replace the DynaBeans with the generated  
> Classes, this might meet your requirements. If not, then the code  
> will at least present you with an example on how to build a mapping
>
> file at runtime.
>
> I will check in the code later today. You can find it in the source
>
> trunk, in package "org.hibernatespatial.pojo". Examples on how to
> use  
> it can be found in the (very preliminary) test classes in package  
> "org.hibernatespatial.test.pojo" (Class TestPojoUtility).
>
> Please not that this feature is not yet complete.
>
> Regards,
>
> Karel
>
>
> On 25 Feb 2008, at 06:44, [hidden email] wrote:
>
> > Hello All,
> >
> > Is there I way that I can avoid using a class's hbm.xml file and  
> > instead
> > provide that information at runtime?
> >
> > For example, I have a DynaBean that I'd like to persist.  I can  
> > discover
> > at runtime all the information that is in the hbm file, I just
> need a
> > way provide it to hibernate w/o going through a XML file.
> >
> > Thanks!
> >
> > --john
> >
> > _______________________________________________
> > hibernatespatial-users mailing list
> > [hidden email]
> > http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/ 
> > hibernatespatial-users
>
> _______________________________________________
> hibernatespatial-users mailing list
> [hidden email]
> http://www.hibernatespatial.org/cgi-
> bin/mailman/listinfo/hibernatespatial-users
>
_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users
Karel Maesen

Re: way to specify class's hibernate mapping at runtime?

Reply Threaded More More options
Print post
Permalink
Hi john,

On 06 Mar 2008, at 05:57, [hidden email] wrote:

> Thanks Karel, I'm just now getting back to this.  So it looks like  
> I can
> construct a DOM  and pass it to the session:
>

A small correction: the DOM is constructed in memory, read out in a  
String and this is added to the Hibernate Configuration.

> Configuration config = new Configuration();
> config.addXML(mappingdocument.asXML());
> this.sessionFactory = config.configure().buildSessionFactory();
>
> Does this DOM look just like the .hbm.xml file?  It doesn't look like
> the sessionFactory configuration is included here (data from
> hibernate.cfg.xml) - how is it added?

Yes, the DOM can contain all the elements that are legal in a mapping  
file, and it is constructed using the DOM4j library. I think only  
mappings can be added this way, not SessionFactory config settings:  
see the addXML() method documentation.

>
> On a separate topic - do you have a version of the basic tutorial that
> uses annotations rather than the Class hbm.xml file?

Not yet, but it is on my To-do list.  In the mean time you could  
check some of the other posts on the mailing list. Some contain code  
snippets using annotations. (the Nabble archive is a good tool for  
this: http://www.nabble.com/Hibernate-Spatial---Users-f27246.html).


Regards,

Karel



_______________________________________________
hibernatespatial-users mailing list
[hidden email]
http://www.hibernatespatial.org/cgi-bin/mailman/listinfo/hibernatespatial-users