-->
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: How to access the Configuration from JMX ?
PostPosted: Thu Sep 30, 2004 5:06 am 
Newbie

Joined: Thu Sep 30, 2004 4:36 am
Posts: 4
Location: Gent
Hi,

In our application we frequently need to read the column width of a string property (typically for validation and for measuring the width of an editable field in a GUI).
I already discovered that this information is available by navigation from the Configuration class, e.g. for a class 'Company' and property 'name'

[quote]
<property
column="COMPANYNAME"
length="64"
name="name"
type="string"
/>
[/quote]

we can find the value "64" using

[code]
Configuration
.getClassMapping("Company")
.getProperty("name")
.getColumnSpan()
[/code]

However, I packaged all Hibernate-related stuff in a JBoss MBean, as described in one of the Wiki articles. Now I can access the SessionFactory
through JNDI lookup, but I can't figure out how to access its Configuration.
So I dug in the source code and found out that the SessionFactory is
built from a temporary Configuration that is no longer accessible.

Is there a clean way to find the Configuration that was used to build the
SessionFactory ? Or is there another way to read property attributes
at runtime ?

Thanks for any help !


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 13, 2004 2:06 pm 
Newbie

Joined: Thu Mar 04, 2004 2:41 pm
Posts: 2
I use the following to create a configuration that's similar to the original configuration object - let me know if you find a better way. Also, this is broken for me on hibernate 2.1.6 - anybody have an idea why it would process most of my mapping files, then get the exception shown below the code? I checked the jar used in the EAR and the mapping file is in there.

Wayne

------------------
Code:
   private static Configuration hCfg = null;

   public static Configuration getNewConfig()
   {
      Configuration newCfg = null;
      Properties props = Environment.getProperties();
      Iterator it = props.keySet().iterator();
      System.err.println("Properties:");
      while (it.hasNext())
      {
         Object obj = (Object) it.next();
         System.err.println(obj.toString() + ": " + props.get(obj).toString());
      }
      try
      {
         Session foo = getSession();
         newCfg = new Configuration();
         newCfg.addProperties(props);
         Map allClasses = aSessionFactory.getAllClassMetadata();
         Iterator acIt = allClasses.keySet().iterator();
         while (acIt.hasNext())
         {
            Class aMappedClass = (Class) acIt.next();
            System.err.println("About to add class to config: " + aMappedClass.getName());
            newCfg.addClass(aMappedClass);
         }
         SessionFactory sf = newCfg.buildSessionFactory();
      }
      catch (HibernateException e)
      {
         e.printStackTrace();
      }
      catch (NamingException e)
      {
         e.printStackTrace();
      }
      return newCfg;
   }

------------


2004-10-13 09:15:12,153 INFO [net.sf.hibernate.cfg.Configuration] Mapping resource: org/pdb/ormapping/Chem_link.hbm.xml
2004-10-13 09:15:12,169 INFO [net.sf.hibernate.cfg.Binder] Mapping class: org.pdb.ormapping.Chem_link -> chem_link
2004-10-13 09:15:12,169 INFO [STDOUT] About to add class to config: org.pdb.ormapping.Em_icos_virus_shells
2004-10-13 09:15:12,169 INFO [net.sf.hibernate.cfg.Configuration] Mapping resource: org/pdb/ormapping/Em_icos_virus_shells.hbm.xml
2004-10-13 09:15:12,169 INFO [net.sf.hibernate.cfg.Binder] Mapping class: org.pdb.ormapping.Em_icos_virus_shells -> em_icos_virus_shells
2004-10-13 09:15:12,169 INFO [STDOUT] About to add class to config: org.pdb.derived.CathNode
2004-10-13 09:15:12,184 INFO [net.sf.hibernate.cfg.Configuration] Mapping resource: org/pdb/derived/CathNode.hbm.xml
2004-10-13 09:15:12,184 INFO [net.sf.hibernate.cfg.Binder] Mapping class: org.pdb.derived.CathNode -> cath_node
2004-10-13 09:15:12,184 INFO [STDOUT] About to add class to config: org.pdb.derived.CathProteinDomainFramgent
2004-10-13 09:15:12,184 INFO [net.sf.hibernate.cfg.Configuration] Mapping resource: org/pdb/derived/CathProteinDomainFramgent.hbm.xml
2004-10-13 09:15:12,200 INFO [STDOUT] net.sf.hibernate.MappingException: Resource: org/pdb/derived/CathProteinDomainFramgent.hbm.xml not found
at net.sf.hibernate.cfg.Configuration.addClass(Configuration.java:352)
at org.pdb.ormapping.util.HibernateUtils.getNewConfig(HibernateUtils.java:53)
at org.pdb.ormapping.util.HibernateUtils.getHibernateConfig(HibernateUtils.java:72)
at org.pdb.util.db.loaders.LoadMetadata.processDerivedTable(LoadMetadata.java:387)
at org.pdb.util.db.loaders.LoadMetadata.generateMetadata(LoadMetadata.java:704)
at org.pdb.util.db.loaders.LoadMetadata.preDatabaseLoad(LoadMetadata.java:72)
at org.pdb.util.db.loaders.DataLoaderUtil.runUpdate(DataLoaderUtil.java:160)
at org.pdb.util.db.loaders.DataLoaderUtil.run(DataLoaderUtil.java:93)
at java.lang.Thread.run(Thread.java:534)


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.