Hibernate:查询元数据 [英] Hibernate: Query Metadata

查看:170
本文介绍了Hibernate:查询元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用基于
a hibernate映射自动生成ExtJS表单的解决方案(我使用基于@Annotations的hibernate逆向工程)。



Hibernate有一个

  getPropertiesInterator()

http://docs.jboss.org/hibernate/core/3.5/api/org/hibernate/mapping/PersistentClass.html#getPropertyIterator%28%29



功能。这可以像这样访问

 ((LocalSessionFactoryBean)sessionFactory).getConfiguration()。getClassMapping(< Classname> .class.getName ())

其中列出了表的属性。我使用这些信息来生成ExtJS输入



varchar => input
text => textarea
etc。



我的问题是,如果有可能有另一种(也许更好)的方法来获取我的休眠配置中的信息?



/ p>

JS

解决方案

我最后使用

  ClassMetadata hibernateMetadata = session.getSessionFactory()。getClassMetadata(fullClassName); 

要通过 [String]获取MetaData ClassName或$ code> Class.class



有了这些信息,你可以这样做...

  String [] propertyNames = hibernateMetadata.getPropertyNames(); 
Type [] propertyTypes = hibernateMetadata.getPropertyTypes();

稍后再分析此信息。



请参阅



http://docs.jboss.org/hibernate/core/3.5/api/org/hibernate/SessionFactory.html#getClassMetadata%28java.lang.String%29



了解更多信息。



Hibernate在他们的文档中甚至有一个例子...



http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/objectstate.html#objectstate-metadata


I'm currently working on a solution to automatically generate ExtJS forms based on a hibernate mapping (I use hibernate reverse engineering for that based on @Annotations).

Hibernate has a

getPropertiesInterator() 

http://docs.jboss.org/hibernate/core/3.5/api/org/hibernate/mapping/PersistentClass.html#getPropertyIterator%28%29

funciton for that. Which is accessible like this

((LocalSessionFactoryBean)sessionFactory).getConfiguration().getClassMapping(<Classname>.class.getName())

Which lists the properties of the table. I use this information to generate ExtJS inputs out of it

varchar => input text => textarea etc.

My question is, if there is maybe another (maybe better) way to get this information out of my hibernate configuration?

Regards

JS

解决方案

I ended up using

ClassMetadata hibernateMetadata = session.getSessionFactory().getClassMetadata(fullClassName);

To get the MetaData either by [String] ClassName or by Class.class

With this information you can do something like this...

String[] propertyNames = hibernateMetadata.getPropertyNames();
Type[] propertyTypes = hibernateMetadata.getPropertyTypes();

And pars this information later on.

See

http://docs.jboss.org/hibernate/core/3.5/api/org/hibernate/SessionFactory.html#getClassMetadata%28java.lang.String%29

for more information.

Hibernate has even an example for this in their docs...

http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/objectstate.html#objectstate-metadata

这篇关于Hibernate:查询元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆