hiberate当中,我建立了Student对象 然后配置Students.htm.xml, onpropertychange的name必须和column的name一样吗

Hiberate(10)
&?xml version=&1.0& encoding=&GBK&?&
&!-- 指定Hibernate配置文件的DTD信息 --&
&!DOCTYPE hibernate-configuration PUBLIC
&-//Hibernate/Hibernate Configuration DTD 3.0//EN&
&http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd&&
&!-- hibernate- configuration是连接配置文件的根元素 --&
&hibernate-configuration&
&session-factory&
&!-- 指定连接数据库所用的驱动 --&
&property name=&connection.driver_class&&com.mysql.jdbc.Driver&/property&
&!-- 指定连接数据库的url,hibernate连接的数据库名 --&
&property name=&connection.url&&jdbc:mysql://localhost/hibernate&/property&
&!-- 指定连接数据库的用户名 --&
&property name=&connection.username&&root&/property&
&!-- 指定连接数据库的密码 --&
&property name=&connection.password&&32147&/property&
&!-- 指定连接池里最大连接数 --&
&property name=&hibernate.c3p0.max_size&&20&/property&
&!-- 指定连接池里最小连接数 --&
&property name=&hibernate.c3p0.min_size&&1&/property&
&!-- 指定连接池里连接的超时时长 --&
&property name=&hibernate.c3p0.timeout&&5000&/property&
&!-- 指定连接池里最大缓存多少个Statement对象 --&
&property name=&hibernate.c3p0.max_statements&&100&/property&
&property name=&hibernate.c3p0.idle_test_period&&3000&/property&
&property name=&hibernate.c3p0.acquire_increment&&2&/property&
&property name=&hibernate.c3p0.validate&&true&/property&
&!-- 指定数据库方言 --&
&property name=&dialect&&org.hibernate.dialect.MySQLInnoDBDialect&/property&
&!-- 根据需要自动创建数据表 --&
&property name=&hbm2ddl.auto&&update&/property&
&!-- 显示Hibernate持久化操作所生成的SQL --&
&property name=&show_sql&&true&/property&
&!-- 将SQL脚本进行格式化后再输出 --&
&property name=&hibernate.format_sql&&true&/property&
&!-- 罗列所有的映射文件 --&
&mapping resource=&org/crazyit/app/domain/News.hbm.xml&/&
&/session-factory&
&/hibernate-configuration&
首先hibernate.cfg.xml 一般放在src目录下。
&Hiberate自带的连接池仅有测试价值,并不推荐在实际项目中使用。实际项目中可以使用C3p0或Proxool连接池,为了使用c3p0连接池或proxool连接池,只需要在这些连接池配置代替hiberate.connection.pool_size配置属性即可。
& &上面的例子使用了c3p0数据源,因此还需要将hiberate-distribution-3.6.0.Final\lib 的optional子目录下的c3p0目录下的JAR包也添加到系统的类加载路径下。
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:202791次
积分:4701
积分:4701
排名:第5479名
原创:242篇
转载:42篇
评论:89条
(3)(11)(5)(1)(1)(1)(2)(13)(18)(3)(2)(5)(2)(12)(1)(1)(1)(1)(6)(9)(13)(19)(3)(1)(1)(3)(4)(30)(27)(34)(2)(1)(1)(3)(8)(32)(2)您所在的位置: &
6.2 管理 SessionFactory
6.2 管理 SessionFactory
电子工业出版社
《轻量级J2EE 企业应用实战: Struts+Spring+Hibernate整合开发》第6章Spring与Hibernate 的整合,这一章主要介绍 Spring与Hibernate 的整合:能简化持久层的访问,大大提高了开发效率。其次重点介绍了 HibernateTemplate 的使用,最后详细介绍了 Spring 的四种事务配置策略。本小节为大家介绍管理 SessionFactory。
6.2 管理 SessionFactory
Hibernate 的 SessionFactory,是单个数据库映射关系编译后的内存镜像,是Hibernate执行持久化访问的基础部分。
大部分情况下,一个 J2EE 应用对应一个数据库。而 Spring 通过 ApplicationContext管理 SessionFac阳町,无须采用单独Hiberate应用所必需的 hibernate.cfg.xml文件。Spring 配置管理 SessionFactory 与数据库的连接。而在实际的J2EE应用中,数据源会采用依赖注入的方式,传给 Hibernate 的 SessionFactory。具体配置如下所示:
&?xml version="1.0" encoding="gb2312"?&&!--Spring配置文件的DTD定义--〉&!DOCTYPE beans PUBLIC"-//SPRiNG//DTDBEAN//EN"''http://www.springframework.org/dtd/spring-beans.dtd"&&!--Spring配置文件的根元素是beans--&&beans&&!--定义数据源,该bean的 ID 为 dataSource--&&bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&&!…指定数据库驱动--〉&property name="driverClassName"&&value&com.mysql.jdbc.Driver&/value&&/property&&!--指定连接数据库的URL--〉&property name="url"&&value&jdbc:mysql://wonder:3306/j2ee&/ value&&/property&&!--root 为数据库的用户名…〉&property name="username"&&value&root&/value&&/property&&!--pass 为数据库密码--〉&property name="password"&&value&pass&/value&&/property&&/bean&&!--定义Hibernate的 SessionFactory--&&beanid="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&&!-- 依赖注入数据源,注入正是上文定义的dataSource&&property name="dataSource"&&ref local="dataSource"/&&/property&&! --mappingResouces属性用来列出全部映射文件〉&property name="mappingResources"&&list&&!--以下用来列出所有的PO 映射文件--&&value&lee/MyTest.hbm.xml&/value&&/list&&/property&&!--定义Hibernate的 SessionFactory的属性一〉&property name="hibernateProperties"&&props&&!--指定Hibernate的连接方法一〉&propkey="hibernate.dialect"&org.hibernate.dialect.MySQLDialect&/prop&&!-- 不同数据库连接,启动时选择create,update, create-drop--&&prop key="hibernate.hbm2ddl.auto"&update&/prop&&/props&&/property&&/bean&&/beans&
SessionFactory由 ApplicationContext管理,井随着应用启动时自动加载,可以被处于 ApplicaionContext管理的任意一个bean引用,比如DAOo Hibernate的数据库访问需要在 Session管理下,而SessionFactory是 Session的工厂。 Spring采用依赖注入为DAO对象注入SessionFactory的引用。
Spring也提供了Hibernate的简化访问方式,Spring采用模板设计模式,提供Hibernate访问与其他持久层访问的一致性。如果需要使用容器管理的数据源,则无须提供数据驱动等信息,只需要提供数据源的JNDI 即可。对上文的SessionFactory只需将dataSource的配置替换成 JNDI 数据源,并将原有的 dataSource Bean 替换成如下所示:
&!--此处配置 JNDI 数据源--〉&bean id="myDataSource" class="org.springframework.jndi.JndiObjectFactoryBean"&&property name="jndiName"&&!--指定数据源的JNDI--&&value&java:comp/env/jdbc/myds&/value&&/property&&/bean&
【责任编辑: TEL:(010)】&&&&&&
关于&&&&&&&&的更多文章
Web Components是W3C定义的新标准,目前还处于草案阶段,但各大
本书描述了黑客用默默无闻的行动为数字世界照亮了一条道路的故事。
讲师: 3人学习过讲师: 7人学习过讲师: 7人学习过
在传统的异构网络环境中,运维人员往往利用各种复杂的
本书共4部分,首先简要介绍了开发相关的基础知识,然
本书将帮助你理解和使用PostgreSQL这一开源数据库系统
本书以最新的ASP.NET 2.0为基础,详细阐述了当前网络开发的经典架构ASP.NET 2.0+XML+CSS的各个知识点,以及SQL Server 2005的相
51CTO旗下网站.Hibernate OGM is released under the LGPL open source license.WarningThis documentation and this project are work in progress.
Please give us feedback onwhat you likewhat you don’t likewhat is confusingCheck
on how to contact us.Hibernate OGM is a young project.
The code, the direction and the documentation are all in flux
and being built by the community.
Join and help us shape it!.You can also:open bug reports in propose improvements on the
join us on IRC to discuss developments and improvements
(#hibernate-dev on freenode.net;
you need to be registered on freenode:
the room does not accept "anonymous" users).give feedback in the forum, IRC or the development mailing listimprove the documentationfix bugs or contribute new featurespropose and code a datastore dialect for your favorite NoSQL engineHibernate OGM’s code is available on GitHub at
..To build the documentation, set the buildDocs property to true:mvn clean install -DbuildDocs=true -s settings-example.xmlTipIf you just want to build the documentation only,
run it from the hibernate-ogm-documentation/manual subdirectory..
In this example we will use Infinispan as the targeted datastore.Add org.hibernate.ogm:hibernate-ogm-infinispan:4.0.0.Beta4
to your project dependencies.
&&&&org.hibernate.ogm
&&&&hibernate-ogm-infinispan
&&&&4.0.0.Beta4
&&&&org.hibernate.javax.persistence
&&&&hibernate-jpa-2.0-api
&&&&1.0.1.Final
NoteWhile Hibernate OGM depends on JPA 2.0,
it is marked as provided in the Maven POM file.
If you run outside a Java EE container,
make sure to explicitly add the dependency.We will use the JPA APIs in this tutorial.Let’s now map our first Hibernate OGM entity.@Entity
public&class&Dog&{
&&&@Id&@GeneratedValue(strategy&=&GenerationType.TABLE,&generator&=&&dog&)
&&&@TableGenerator(
&&&&&&name&=&&dog&,
&&&&&&table&=&&sequences&,
&&&&&&pkColumnName&=&&key&,
&&&&&&pkColumnValue&=&&dog&,
&&&&&&valueColumnName&=&&seed&
&&&public&Long&getId()&{&return&id;&}
&&&public&void&setId(Long&id)&{&this.id&=&id;&}
&&&private&Long&id;
&&&public&String&getName()&{&return&name;&}
&&&public&void&setName(String&name)&{&this.name&=&name;&}
&&&private&String&name;
&&&@ManyToOne
&&&public&Breed&getBreed()&{&return&breed;&}
&&&public&void&setBreed(Breed&breed)&{&this.breed&=&breed;&}
&&&private&Breed&breed;
public&class&Breed&{
&&&@Id&@GeneratedValue(generator&=&&uuid&)
&&&@GenericGenerator(name=&uuid&,&strategy=&uuid2&)
&&&public&String&getId()&{&return&id;&}
&&&public&void&setId(String&id)&{&this.id&=&id;&}
&&&private&String&id;
&&&public&String&getName()&{&return&name;&}
&&&public&void&setName(String&name)&{&this.name&=&name;&}
&&&private&String&name;
}I lied to you, we have already mapped two entities!
If you are familiar with JPA,
you can see that there is nothing specific to Hibernate OGM in our mapping.In this tutorial, we will use JBoss Transactions for our JTA transaction manager.
The final list of dependencies should look like this:
&&&&&&&&org.hibernate.ogm
&&&&&&&&hibernate-ogm-core
&&&&&&&&4.0.0.Beta4
&&&&&&&&org.hibernate.javax.persistence
&&&&&&&&hibernate-jpa-2.0-api
&&&&&&&&1.0.1.Final
&&&&&&&&org.jboss.spec.javax.transaction
&&&&&&&&jboss-transaction-api_1.1_spec
&&&&&&&&1.0.0.Final
&&&&&&&&provided
&&&&&&&&org.jboss.jbossts
&&&&&&&&jbossjta
&&&&&&&&4.16.4.Final
Next we need to define the persistence unit.
Create a META-INF/persistence.xml file.
&?xml&version=&1.0&?&
&xmlns&/xml/ns/persistence&
&&&&&&&&&&&&&xmlns:xsi&http://www.w3.org/2001/XMLSchema-instance&
&&&&&&&&&&&&&xsi:schemaLocation&/xml/ns/persistence&/xml/ns/persistence/persistence_2_0.xsd&
&&&&&&&&&&&&&version&2.0&
&&&&&name&ogm-jpa-tutorial&&transaction-type&JTA&
&&&&&&&&org.hibernate.ogm.jpa.HibernateOgmPersistence
&&&&&&&&&&&&
&&&&&&&&&&&&
&&&&&&&&&&&&&name&hibernate.transaction.jta.platform&
&&&&&&&&&&&&&&&&&&&&&&value&org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform&
Let’s now persist a set of entities and retrieve them.//accessing&JBoss's&Transaction&can&be&done&differently&but&this&one&works&nicely
TransactionManager&tm&=&getTransactionManager();
//build&the&EntityManagerFactory&as&you&would&build&in&in&Hibernate&ORM
EntityManagerFactory&emf&=&Persistence.createEntityManagerFactory(
&&&&&ogm-jpa-tutorial&);
final&Logger&logger&=&LoggerFactory.getLogger(DogBreedRunner.class);
//Persist&entities&the&way&you&are&used&to&in&plain&JPA
tm.begin();
logger.infof(&About&to&store&dog&and&breed&);
EntityManager&em&=&emf.createEntityManager();
Breed&collie&=&new&Breed();
collie.setName(&Collie&);
em.persist(collie);
Dog&dina&=&new&Dog();
dina.setName(&Dina&);
dina.setBreed(collie);
em.persist(dina);
Long&dinaId&=&dina.getId();
em.flush();
em.close();
tm.commit();
//Retrieve&your&entities&the&way&you&are&used&to&in&plain&JPA
tm.begin();
logger.infof(&About&to&retrieve&dog&and&breed&);
em&=&emf.createEntityManager();
dina&=&em.find(Dog.class,&dinaId);
logger.infof(&Found&dog&%s&of&breed&%s&,&dina.getName(),&dina.getBreed().getName());
em.flush();
em.close();
tm.commit();
emf.close();
public&static&TransactionManager&getTransactionManager()&throws&Exception
&&&&Class&?&&tmClass&=&Main.class.getClassLoader().loadClass(JBOSS_TM_CLASS_NAME);
&&&&return&(TransactionManager)&tmClass.getMethod(&transactionManager&).invoke(null);
}NoteSome JVM do not handle mixed IPv4/IPv6 stacks properly (older
if you experience trouble starting the Infinispan cluster,
pass the following property: -Djava.net.preferIPv4Stack=true
to your JVM or upgrade to a recent JDK version.
jdk7u6 (b22) is known to work on Max OS X.A working example can be found in Hibernate OGM’s distribution under
hibernate-ogm-documentation/examples/gettingstarted.What have we seen?Hibernate OGM is a JPA implementation
and is used as such both for mapping and in API usageIt is configured as a specific JPA provider:
org.hibernate.ogm.jpa.HibernateOgmPersistenceLet’s explore more in the next chapters.NoteHibernate OGM defines an abstraction layer
represented by DatastoreProvider and GridDialect
to separate the OGM engine from the datastores interaction.
It has successfully abstracted various key/value stores and MongoDB.
We are working on testing it on other NoSQL families.In this chapter we will will explore:the general architecturehow the data is persisted in the NoSQL datastorehow we support JP-QL queriesLet’s start with the general architecture. how the data is structured.The particularities between NoSQL stores are abstracted
by the notion of a DatastoreProvider and a GridDialect.DatastoreProvider abstracts how to start
and maintain a connection between Hibernate OGM and the datastore.GridDialect abstracts how data itself including association
is persisted.Think of them as the JDBC layer for our NoSQL stores.Other than these, all the Create/Read/Update/Delete (CRUD) operations
are implemented by the Hibernate ORM engine
(object hydration and dehydration, cascading, lifecycle etc).As of today, we have implemented four datastore providers:a Map based datastore provider (for testing)an Infinispan based datastore provider to persist your entities in Infinispana Ehcache based datastore provider to persist your entities in Ehcachea MongoDB based datastore provider to persist data in a MongoDB databaseTo implement JP-QL queries, Hibernate OGM parses the JP-QL string
and calls the appropriate translator functions to build a native query.
If the query is too complex for the native capabilities of the NoSQL store,
the Teiid query engine is used as an intermediary engine
to implement the missing features (typically joins between entities, aggregation).
Finally, if the underlying engine does not have any query support,
we use Hibernate Search as an external query engine.Reality is a bit more nuanced, we will discuss the subject of querying
in more details in .Hibernate OGM best works in a JTA environment.
The easiest solution is to deploy it on a Java EE container.
Alternatively, you can use a standalone JTA TransactionManager.
We explain how to in .Let’s now see how and in which structure data is persisted in the NoSQL data store. for more details.But to answer your question,
we have finished the skeleton of the architecture
as well as the JP-QL parser implementation.
The Hibernate Search query translator can execute simple queries already.
However, we do not yet have a NoSQL specific query translator
but the approach is quite clear to us.
Teiid for complex queries is also not integrated
but work is being done to facilitate that integration soon.
Native Hibernate Search queries are fully supported.Hibernate OGM favors ease of use and convention over configuration.
This makes its configuration quite simple by default. for more info)there is no DDL scheme generation options (hbm2ddl)
as NoSQL generally do not require schemasif you use JTA (which we recommend), you will need to set the JTA platformYou also need to configure which NoSQL datastore you want to use
and how to connect to it.
We will detail how to do that later in .
In this case, we have used the defaults settings for Infinispan.From there, simply bootstrap JPA the way you are used to with Hibernate ORM:via Persistence.createEntityManagerFactoryby injecting the EntityManager / EntityManagerFactory in a Java EE containerby using your favorite injection framework (CDI - Weld, Spring, Guice))You also need to configure which NoSQL datastore you want to use
and how to connect to it.
We will detail how to do that later in .
In this case, we have used the defaults settings for Infinispan..
For example, in JBoss AS,
use org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform.In your persistence.xml, you also need to define an existing datasource.
It is not needed by Hibernate OGM
and won’t be used but the JPA specification mandates this setting..Otherwise, most options from Hibernate ORM and Hibernate Search are applicable
when using Hibernate OGM.
You can pass them as you are used to do
either in your persistence.xml file, your hibernate.cfg.xml file
or programmatically.More interesting is a list of options that do not apply to Hibernate OGM
and that should not be set:hibernate.dialecthibernate.connection.* and in particular hibernate.connection.provider_classhibernate.show_sql and hibernate.format_sqlhibernate.default_schema and hibernate.default_cataloghibernate.use_sql_commentshibernate.jdbc.*hibernate.hbm2ddl.auto and hibernate.hbm2ddl.import_file.In
we’ll discuss how to store your Lucene indexes in Infinispan.
This is useful even if you don’t plan to use Infinispan as your primary data store..You can download the pre-packaged module from:Unpack the archive into the modules folder of your JBoss AS 7.2 installation.
The modules included are:org.hibernate:ogm, containing the core OGM library and the infinispan datastore provider.org.hibernate.ogm.ehcache:main, containing the ehcache datastore provider.org.hibernate.ogm.mongodb:main, containing the mongodb datastore provider.org.hibernate:main, containing the latest hibernate ORM libraries compatible with OGM.WarningThe org.hibernate:main module changes the version of Hibernate ORM
included in the default JBoss AS 7.2.There are two ways to include the dependencies in your project:Using the manifestAdd this entry to the MANIFEST.MF in your archive:Dependencies: org.hibernate:ogm servicesUsing jboss-deployment-structure.xmlThis is a proprietary JBoss AS descriptor.
Add a WEB-INF/jboss-deployment-structure.xml in your archive with content:
&&&&&&&&&&&&&name&org.hibernate&&slot&ogm&&services&export&&
More information about the descriptor can be found in the
.Currently Hibernate OGM supports the following datastores:Map: stores data in an in-memory Java map to store data.
Use it only for unit tests.Infinispan: stores data into
(data grid)Ehcache: stores data into
(cache)MongoDB: stores data into
(document store)More are planned, if you are interested,
come talk to us (see ).Hibernate OGM interacts with NoSQL datastores via two contracts:a datastore provider which is responsible for
starting and stopping the connection(s) with the datastore
and prop up the datastore if neededa grid dialect which is responsible for
converting an Hibernate OGM operation into a datastore specific operationThe main thing you need to do is to configure which datastore provider you want to use.
This is done via the hibernate.ogm.datastore.provider option.
Possible values are the fully qualified class name
of a DatastoreProvider implementation
or one preferably of the following shortcuts:map: stores data in an in-memory Java map to store data.
Use it only for unit tests.infinispan: stores data into
(data grid)ehcache: stores data into
(cache)mongodb: stores data into
(document store)neo4j: stores data into
(graph)You also need to add the relevant Hibernate OGM module in your classpath.
In maven that would look like:
&&&&org.hibernate.ogm
&&&&hibernate-ogm-infinispan
&&&&4.0.0.Beta4
We have respectively
hibernate-ogm-infinispan, hibernate-ogm-ehcache, hibernate-ogm-mongodb and hibernate-ogm-neo4j.
The map datastore is included in the Hibernate OGM engine module.By default, a datastore provider chooses the best grid dialect transparently
but you can manually override that setting
with the hibernate.ogm.datastore.grid_dialect option.
Use the fully qualified class name of the GridDialect implementation.
Most users should ignore this setting entirely and live happy..
for the guru level performance tuning and customizations.An Infinispan configuration file is an XML file complying with the I
the basic structure is shown in the following example:,
specifically look for Discovery Protocols to customize the detection of peer nodes.Nowadays, the JVM defaults to use IPv6
this will work fine with JGroups, but only if you configured IPv6 correctly.
It is often useful to force the JVM to use IPv4.It is also useful to let JGroups know which networking inter
especially if you have multiple interfaces it might not guess correctly.
for more advanced configuration options.),
needs some place to store the indexes for its embedded Apache Lucene engine.A common place to store these indexes is the filesystem
which is the default for Hibernate S
however if your goal is to scale your NoSQL engine on multiple nodes
you need to share this index.
Network sharing filesystems are a possibility but we don’t recommended that.
Often the best option is to store the index
in whatever NoSQL database you are using (or a different dedicated one).TipYou might find this section useful even if you don’t intend to store your data in Infinispan.The Infinispan project provides an adaptor to plug into Apache Lucene,
so that it writes the indexes in Infinispan and searches data in it.
Since Infinispan can be used as an application cache to other NoSQL storage engines
by using a CacheStore (see )
you can use this adaptor to store the Lucene indexes
in any NoSQL store supported by Infinispan:CassandraFilesystem (but locked correctly at the Infinispan level)MongoDBHBaseJDBC databasesJDBMBDBJEA secondary (independent) Infinispan gridAny Cloud storage service
How to configure it? Here is a simple cheat sheet to get you started with this type of setup:Add org.hibernate:hibernate-search-infinispan:4.4.0.Beta1 to your dependenciesset these configuration properties:hibernate.search.default.directory_provider = infinispanhibernate.search.default.exclusive_index_use = falsehibernate.search.infinispan.configuration_resourcename = [infinispan configuration filename]The referenced Infinispan configuration should define a CacheStore
to load/store the index in the NoSQL engine of choice.
It should also define three cache names:.. is a document oriented datastore
written in C++ with strong emphasis on ease of use..
This option is case insensitive and the default value is ACKNOWLEDGED. is a robust (fully ACID) transactional property graph database.
This kind of databases are suited for those type of problems that can be represented with a graph
like social relationships or road maps for example.At the moment only the support for the embeedded Neo4j is included in OGM.This is our first version and a bit experimental. In particular we plan on using node navigation much more than index lookup in a future version.2. Add the following properties:
hibernate.ogm.datastore.provider = neo4j_embedded
hibernate.ogm.neo4j.database.path = C:\example\mydb
TODO:Talk about supported approaches (properties, embedded objects, inheritance)Talk about associationsTalk about identifier recommendations or the documentation of Hibernate ORM.
Let’s concentrate of the features that differ
or are simply not supported by Hibernate OGM.The various inheritance strategies are not supported by Hibernate OGM,
only the table per concrete class strategy is used.
f This is not so much a limitation
but rather an acknowledgment of the dynamic nature of NoSQL schemas.
If you feel the need to support other strategies,
let us know (see ).
Simply do not use @Inheritance nor @DiscriminatorColumn.Secondary tables are not supported by Hibernate OGM at the moment.
If you have needs for this feature, let us know (see ).All SQL related constructs
as well as HQL centered mapping are not supported in Hibernate OGM.
Here is a list of feature that will not work:Named queriesNative queriesAll standard JPA id generators are supported: IDENTITY, SEQUENCE, TABLE and AUTO.
If you need support for additional generators,
let us know (see ).
We recommend you use a UUID based generator
as this type of generator allows maximum scalability to the underlying data grid
as no cluster-wide counter is necessary. for more information.Keep in mind that collections with many entries won’t perform very well
in Hibernate OGM (at least today)
as all of the association navigation for a given entity is stored in a single key.
If your collection is made of 1 million elements,
Hibernate OGM stores 1 million tuples in the association key.To query a NoSQL database is a complex feat,
especially as not all NoSQL solutions support all forms of query.
One of the goals of Hibernate OGM is to deal with this complexity
so that users don’t have to.
However, that’s not yet all implemented
and depending on your use case
there might be better approaches you can take advantage of.If you skipped to this section without reading ,
I’d suggest to read at least
as it will greatly help you choosing a query approach.7.1. Using JP-QLFor Hibernate OGM we developed a brand new JP-QL parser
which is already able to convert simple queries
using Hibernate Search under the precondition that:no join, aggregation, or other relational operations are impliedyou are using the Hibernate Session API (JPA integration is coming)the target entities and properties are indexed by Hibernate Search
(no validation is happening today)We do realize these are strong limitations,
so while it might be interesting to try it out,
for real usage we suggest for now to use either Hibernate Search full-text queries
or the native query technology of the NoSQL storage you are using.To provide an example of what kind of queries would work:Example 7.1. Example of trivial Hibernate Query remapped on Hibernate SearchQuery&query&=&session
&&&&.createQuery(&from&Hypothesis&h&where&h.description&=&:desc&)
&&&&.setString(&desc&,&&tomorrow&it's&going&to&rain&);@Entity&@Indexed
public&class&Hypothesis&{
&&&&public&String&getId()&{&return&id;&}
&&&&public&void&setId(String&id)&{&this.id&=&id;&}
&&&&private&String&id;
&&&&@Field(analyze=Analyze.NO)
&&&&public&String&getDescription()&{&return&description;&}
&&&&public&void&setDescription(String&description)&{&this.description&=&description;&}
&&&&private&String&description;
}.While the potential of Lucene queries is very high,
it’s not suited for all use cases
Let’s see some of the limitations of Lucene Queries as our main query engine:Lucene doesn’t support Joins.
Any to-One relations can be mapped fine,
and the Lucene community is making progress on other forms,
but restrictions on OneToMany or ManyToMany can’t be implemented today.Since we apply changes to the index at commit time,
your updates won’t affect queries until you commit
(we might improve on this).While queries are extremely fast, write operations are not as fast
(but we can make it scale).7.3. Using the Criteria APIThis is not implemented yet.

我要回帖

更多关于 property 的文章

 

随机推荐