Giter Club home page Giter Club logo

Comments (4)

graemerocher avatar graemerocher commented on June 13, 2024

As mentioned in http://gorm.grails.org/6.0.x/hibernate/manual/index.html#outsideGrails you need to declare the necessary dependencies. The dependencies that are not in the example you have that are mentioned as being necessary in the docs are the connection pool to use:

runtime "org.apache.tomcat:tomcat-jdbc:8.5.0"
runtime "org.apache.tomcat.embed:tomcat-embed-logging-log4j:8.5.0"

The connection pool can be commons-dbcp, tomcat pool or hikari. If you don't specify a connection pool then a org.springframework.jdbc.datasource.DriverManagerDataSource is used, which creates a new connection to the database each time you request a connect.

The problem with this when you use an in-memory database is that h2 is creating a new in-memory database each time a connection is requested. So the tables that were created previously are lost. If you were using a normal database (mysql, postgres or h2 file based database) your example would work fine.

It is the combination of DriverManagerDataSource, which creates and initialises a brand new in-memory database each time a connection is requested (because it is not a pool), and h2 in-memory that causes the issue you are seeing.

That is why we include a connection pool in the list of necessary dependencies, since people are likely to stumble into this (as you have) and also any real production application would use a pool.

from gorm-hibernate5.

ysb33r avatar ysb33r commented on June 13, 2024

RIght. I'm going to create a PR which describes this a bit better in the docs.

from gorm-hibernate5.

ysb33r avatar ysb33r commented on June 13, 2024

On that note of docs isn't the use of implements GormEntity<Person> redundant? I thought @Entity effectively does that.

from gorm-hibernate5.

graemerocher avatar graemerocher commented on June 13, 2024

It is, but some IDEs use the fact that the class is in grails-app/domain to enable code completion. So by being explicit about implementing the trait you are more likely to obtain completions etc.

from gorm-hibernate5.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.