My db:
CREATE TABLE `ggloor`.`teams` (
`idteam` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(45) NULL,
PRIMARY KEY (`idteam`));
Settings in applicatin.yml
hibernate:
cache:
queries: false
use_second_level_cache: true
use_query_cache: false
region.factory_class: org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
dataSource:
pooled: true
jmxExport: true
driverClassName: com.mysql.jdbc.Driver
username: root
password: 1111
environments:
development:
dataSource:
dbCreate: create-drop
url: jdbc:mysql://localhost:3306/ggloor?useSSL=false
test:
dataSource:
dbCreate: create-drop
url: jdbc:mysql://localhost:3306/ggloor?autoreconnect=true;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
production:
dataSource:
dbCreate: create-drop
url: jdbc:mysql://localhost:3306/ggloor?autoreconnect=true;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
properties:
jmxEnabled: true
initialSize: 5
maxActive: 50
minIdle: 5
maxIdle: 25
maxWait: 10000
maxAge: 600000
timeBetweenEvictionRunsMillis: 5000
minEvictableIdleTimeMillis: 60000
validationQuery: SELECT 1
validationQueryTimeout: 3
validationInterval: 15000
testOnBorrow: true
testWhileIdle: true
testOnReturn: false
jdbcInterceptors: ConnectionState
defaultTransactionIsolation: 2 # TRANSACTION_READ_COMMITTED
Created domain
package testgrails12
class Teams {
Integer idteam
String name
static constraints = {
}
}
Controller
package testgrails12
class Teams {
Integer idteam
String name
static constraints = {
}
static mapping = {
id column: 'idteam', sqlType: 'INT(11)', insertable: false, updateable: false
}
}
I get an error at the execution stage
Error 500: Internal Server Error URI /bdconnect/index Class com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException Message null Caused by Unknown column 'teams0_.id' in 'field list'
I tried to create hibernate.cfg.xml, Teams.hbm.xml in the conf folder, this did not work.
How to set everything up correctly? Work stopped =(
Error after add mapping
2017-03-29 19:30:34.954 ERROR --- [ost-startStop-1] o.s.b.c.embedded.tomcat.TomcatStarter : Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'grailsCacheFilter': Cannot create inner bean '(inner bean)#4bafa64a' of type [grails.plugin.cache.web.filter.simple.MemoryPageFragmentCachingFilter] while setting bean property 'filter'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name '(inner bean)#4bafa64a': Unsatisfied dependency expressed through method 'setUrlMappingsHandlerMapping' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'urlMappingsHandlerMapping': Unsatisfied dependency expressed through method 'setWebRequestInterceptors' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'openSessionInViewInterceptor': Cannot resolve reference to bean 'hibernateDatastore' while setting bean property 'hibernateDatastore'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateDatastore': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.grails.orm.hibernate.HibernateDatastore]: Constructor threw exception; nested exception is org.hibernate.MappingException: Repeated column in mapping for entity: testgrails12.Teams column: idteam (should be mapped with insert="false" update="false") 2017-03-29 19:30:35.003 ERROR --- [ main] o.s.boot.SpringApplication : Application startup failed
hibernate
, but in your class definition the field is calledteamid
, in your database screenshot its calledidteam
and your error message names the fieldid
. Looks inconsistent to me. – ventiseis@GeneratedValue
annotation? – ventiseis