Search code examples
grailsgrails-ormgrails-domain-class

DB connectivity fails in grails 5 application with error creating hibernateDatastore


I am upgrading an application to grails-5. I have moved my DB connectivity information from a custom DataSource.groovy to application.yml. environments: development: dataSource: dbCreate: update url: jdbc:mysql://hostName:port/DbName?user=x;password=y

The credentials are correct however the application fails to start up and throws the following error.

springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateDatastore': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to i
nstantiate [org.grails.orm.hibernate.HibernateDatastore]: Constructor threw exception; nested exception is org.hibernate.MappingException: Could not determine type for: org.springframework.transaction.PlatformTransactionManager, at t
able: <<table_name>>, for columns: [org.hibernate.mapping.Column(transaction_manager)]

Solution

  • If you have @Transactional on a domain class (which there is no good reason to do) that will result in a property named transactionManager being added to the class. That is required in order for the transaction management logic to be carried out. The problem is that properties in a domain class are by default mapped to the database unless they are configured as transient.

    You should remove the @Transactional annotation from the domain class and move any transactional logic wherever transactions are being managed, which frequently is in a transactional Service.