////
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
////

If you wish to use GORM for Hibernate outside of a Grails application you should declare the necessary dependencies for GORM and the database you are using, for example in Gradle:

[source,groovy,subs="attributes"]
----
compile "org.apache.grails.data:grails-data-hibernate5-core:{version}"
runtime "com.h2database:h2:1.4.192"
runtime "org.apache.tomcat:tomcat-jdbc:8.5.0"
runtime "org.apache.tomcat.embed:tomcat-embed-logging-log4j:8.5.0"
runtime "org.slf4j:slf4j-api:1.7.10"
----

NOTE: The above example also uses the https://www.h2database.com[H2 Database] and Tomcat connection pool.
However other pool implementations are supported including `commons-dbcp`, `tomcat pool` or `hikari`.
If a connection pool is not specified `org.springframework.jdbc.datasource.DriverManagerDataSource` is used,
which creates a new connection to the database each time you request a connect.
The latter will probably cause issues with an H2 in-memory database in that it will create a new in-memory
database each time a connection is requested, losing previously created tables.
Normal databases (`MySql`, `Postgres` or even file-based `H2`) are not affected.

Then create your entities in the `src/main/groovy` directory and annotate them with the `grails.gorm.annotation.Entity` annotation:

[source,groovy]
----
@Entity
class Person implements GormEntity<Person> { // <1>
    String firstName
    String lastName
    static constraints = {
        firstName blank:false
        lastName blank:false
    }
}
----
<1> Use of `GormEntity` is merely to aid IDE support outside of Grails.
When used inside a Grails context, some IDEs will use the
`grails-app/domain` location as a hint to enable code completion.

Then you need to place the bootstrap logic somewhere in your application which uses `HibernateDatastore`:

[source,groovy]
----
import org.grails.orm.hibernate.HibernateDatastore
Map configuration = [
    'hibernate.hbm2ddl.auto':'create-drop',
    'dataSource.url':'jdbc:h2:mem:myDB'
]
HibernateDatastore datastore = new HibernateDatastore( configuration, Person)
----

For more information on how to configure GORM see the <<configuration, Configuration>> section.
