On grails 2.4.3 and postgresql as the database I have:
class ClassA {
Set classB = []
static belongsTo = [classC: ClassC]
static hasMany = [classB: ClassB]
}
and:
#EqualsAndHashCode
class ClassB implements Serializable {
ClassA classA
Integer number
static belongsTo = [classA: ClassA]
static mapping = {
id composite: ['number', 'classA']
}
And I'm getting this weird error:
[localhost-startStop-1] ERROR context.GrailsContextLoaderListener - Error initializin
the application: Error creating bean with name 'transactionManagerPostProcessor':
Initialization of bean failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting
bean property 'sessionFactory'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'sessionFactory': Invocation of init method failed; nested exception is
java.lang.NullPointerException Message: Error creating bean with name
'transactionManagerPostProcessor': Initialization of bean failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting
bean property 'sessionFactory'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'sessionFactory': Invocation of init method failed; nested exception is
java.lang.NullPointerException Line | Method ->> 266 | run in
java.util.concurrent.FutureTask - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - | 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor | 617 |
run . . . in java.util.concurrent.ThreadPoolExecutor$Worker ^ 745 | run in
java.lang.Thread
What is going on? What I am doing wrong?
not sure, what the message means, but this is wrong:
Set ClassB = []
it should be
Set<ClassB> classB = new HashSet<>()
UPDATE:
see the refdoc. the fields should be of primitive types I'd say.
try converting extracting a property out of the ClassB instance:
#EqualsAndHashCode
class ClassB implements Serializable {
ClassA classA
String someAProp
Integer number
void setClassA( ClassA a ){
classA = a
someAProp = a.someProp
}
static belongsTo = [classA: ClassA]
static mapping = {
id composite: ['number', 'someAProp']
}
}
Related
I have the following code in Grails:
public LibraryItem createLibraryItemWithValues(ProjectItem projectItem) {
def libraryitem = new LibraryItem ()
libraryitem.name = projectItem.name
libraryitem.itemtype = projectItem.itemtype.itemtype
libraryitem.description = projectItem.description
List<LibraryCategoryValue> libCatValues = new ArrayList<LibraryCategoryValue>();
for (def pcv : projectItem.categoryvalues) {
libCatValues.add(pcv.librarycategoryvalue);
}
if (libraryitem.id != null && !libraryitem.isAttached()) {
libraryitem.attach()
}
libCatValues.each{
it.addToLibraryitems(libraryitem)
}
return libraryitem.save()
}
The class LibraryCategoryValue
package ch.fhnw.accelerom.project.library
import ch.fhnw.accelerom.project.ItemType
import ch.fhnw.accelerom.project.TranslatableObject
class LibraryCategoryValue extends TranslatableObject {
SortedSet<LibraryItem> libraryitems
static belongsTo = [librarycategory:LibraryCategory]
static hasMany = [libraryitems: LibraryItem]
static constraints = {
}
}
My problem is, that I get the exception "IndexOutOfBoundsException" with the detailMessage "Index:1, Size 0" and suppressedExceptions "Collections$UnmodifiableRandomAccessList" with Value "size = 0" when I run this code in the service but there is no exception, when I run this code in the controller. The exception comes from the command it.addToLibraryitems(libraryitem), respektive, when I comment this line, than no exception occur. Can someone give me a hint, what the problem could be?
Thanks in advance.
Edit:
I now initialized libraryitems in the class with
SortedSet<LibraryItem> libraryitems = []
but now I get the following error when I start the application
ERROR context.GrailsContextLoader - Error initializing the application: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.InstantiationException: could not instantiate test objectch.fhnw.accelerom.project.library.LibraryCategoryValue
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.InstantiationException: could not instantiate test objectch.fhnw.accelerom.project.library.LibraryCategoryValue
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.InstantiationException: could not instantiate test objectch.fhnw.accelerom.project.library.LibraryCategoryValue
... 4 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.InstantiationException: could not instantiate test objectch.fhnw.accelerom.project.library.LibraryCategoryValue
... 4 more
Caused by: org.hibernate.InstantiationException: could not instantiate test objectch.fhnw.accelerom.project.library.LibraryCategoryValue
... 4 more
Caused by: java.lang.reflect.InvocationTargetException
... 4 more
Caused by: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '[]' with class 'java.util.ArrayList' to class 'java.util.SortedSet' due to: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: java.util.SortedSet()
at ch.fhnw.accelerom.project.library.LibraryCategoryValue.<init>(LibraryCategoryValue.groovy:7)
... 4 more
Edit 2:
I also tried to initialize libraryitems with
SortedSet<LibraryItem> libraryitems = new TreeSet<LibraryItem>()
But then I'm back on the first exception "IndexOutOfBoundsException". I'm so wondering, why there is no problem, when this code is in the controller. What's the difference between a service and a controller in this case?
Try using a transactional service method:
import grails.transaction.Transactional
class LibraryService {
#Transactional
public LibraryItem createLibraryItemWithValues(ProjectItem projectItem) {
def libraryitem = new LibraryItem()
libraryitem.name = projectItem.name
libraryitem.itemtype = projectItem.itemtype.itemtype
libraryitem.description = projectItem.description
projectItem.categoryvalues*.librarycategoryvalue.each {
it.addToLibraryitems(libraryitem)
}
return libraryitem.save()
}
}
Since you're creating a new LibraryItem it's ID will always be null until you save it. In most cases you don't need to use attach(), so I removed all of that code.
I tried to use oauth plugin 2.6.1 on a Grails 2.4.4 blank application.
I followed instruction on documentation for quickstart, however when I start the application I have that stacktrace:
Message: Error creating bean with name 'grails.plugin.databasemigration.DbdocController': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'instanceControllerTagLibraryApi': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.codehaus.groovy.grails.plugins.web.api.ControllerTagLibraryApi.setTagLibraryLookup(org.codehaus.groovy.grails.web.pages.TagLibraryLookup); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gspTagLibraryLookup': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uk.co.desirableobjects.oauth.scribe.OauthTagLib': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'oauthService': Invocation of init method failed; nested exception is uk.co.desirableobjects.oauth.scribe.exception.InvalidOauthProviderException: [:] configured as an API for facebook does not appear to be a valid Class. It should be a class extending from the org.scribe.builder.Api class
Line | Method
->> 262 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'instanceControllerTagLibraryApi': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.codehaus.groovy.grails.plugins.web.api.ControllerTagLibraryApi.setTagLibraryLookup(org.codehaus.groovy.grails.web.pages.TagLibraryLookup); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gspTagLibraryLookup': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uk.co.desirableobjects.oauth.scribe.OauthTagLib': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'oauthService': Invocation of init method failed; nested exception is uk.co.desirableobjects.oauth.scribe.exception.InvalidOauthProviderException: [:] configured as an API for facebook does not appear to be a valid Class. It should be a class extending from the org.scribe.builder.Api class
->> 262 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by BeanCreationException: Could not autowire method: public void org.codehaus.groovy.grails.plugins.web.api.ControllerTagLibraryApi.setTagLibraryLookup(org.codehaus.groovy.grails.web.pages.TagLibraryLookup); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gspTagLibraryLookup': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uk.co.desirableobjects.oauth.scribe.OauthTagLib': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'oauthService': Invocation of init method failed; nested exception is uk.co.desirableobjects.oauth.scribe.exception.InvalidOauthProviderException: [:] configured as an API for facebook does not appear to be a valid Class. It should be a class extending from the org.scribe.builder.Api class
->> 262 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'gspTagLibraryLookup': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uk.co.desirableobjects.oauth.scribe.OauthTagLib': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'oauthService': Invocation of init method failed; nested exception is uk.co.desirableobjects.oauth.scribe.exception.InvalidOauthProviderException: [:] configured as an API for facebook does not appear to be a valid Class. It should be a class extending from the org.scribe.builder.Api class
->> 262 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'uk.co.desirableobjects.oauth.scribe.OauthTagLib': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'oauthService': Invocation of init method failed; nested exception is uk.co.desirableobjects.oauth.scribe.exception.InvalidOauthProviderException: [:] configured as an API for facebook does not appear to be a valid Class. It should be a class extending from the org.scribe.builder.Api class
->> 262 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'oauthService': Invocation of init method failed; nested exception is uk.co.desirableobjects.oauth.scribe.exception.InvalidOauthProviderException: [:] configured as an API for facebook does not appear to be a valid Class. It should be a class extending from the org.scribe.builder.Api class
->> 262 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by InvalidOauthProviderException: [:] configured as an API for facebook does not appear to be a valid Class. It should be a class extending from the org.scribe.builder.Api class
->> 48 | afterPropertiesSet in uk.co.desirableobjects.oauth.scribe.OauthService
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 262 | run in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run . . . in java.lang.Thread
The error seems quite clear, but I don't understand if it's a configuration problem.
This is my configuraton in Config.groovy:
oauth {
providers {
twitter {
api = TwitterApi
key = 'my-key'
secret = 'my-secret'
}
}
}
Make sure you have imported the class FacebookApi in your Config.groovy
So, I've just created a brand new grails app, created one Domain with a few fields, and then a controller and a set of views based from the domain (using grails built in generate commands).
I then attempt to run this and get the following error, any clues?: -
| Error 2013-10-24 12:08:11,643 [localhost-startStop-1] ERROR context.GrailsContextLoader - Error executing bootstraps: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Can not set java.lang.String field test.PC.MyName to java.lang.Class
Message: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Can not set java.lang.String field test.PC.MyName to java.lang.Class
Line | Method
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 166 | run in java.util.concurrent.FutureTask
| 1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 603 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run . . . in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Can not set java.lang.String field test.PC.MyName to java.lang.Class
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 166 | run in java.util.concurrent.FutureTask
| 1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 603 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run . . . in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Can not set java.lang.String field test.PC.MyName to java.lang.Class
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 166 | run in java.util.concurrent.FutureTask
| 1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 603 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run . . . in java.lang.Thread
Caused by IllegalArgumentException: Can not set java.lang.String field test.PC.MyName to java.lang.Class
->> 6 | doCall in test.PC$__clinit__closure1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 334 | innerRun in java.util.concurrent.FutureTask$Sync
| 166 | run . . . in java.util.concurrent.FutureTask
| 1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 603 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
At the risk over overfilling this with data, a quick google suggests this could be something to do with my datasource? If so my datasource file looks like so which is the standard template for when a project is first generated so should work..? : -
dataSource {
pooled = true
driverClassName = "org.h2.Driver"
username = "sa"
password = ""
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
// environment specific settings
environments {
development {
dataSource {
dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
}
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
}
}
production {
dataSource {
dbCreate = "update"
url = "jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
pooled = true
properties {
maxActive = -1
minEvictableIdleTimeMillis=1800000
timeBetweenEvictionRunsMillis=1800000
numTestsPerEvictionRun=3
testOnBorrow=true
testWhileIdle=true
testOnReturn=true
validationQuery="SELECT 1"
}
}
}
}
It also mentions failures with the bootstrap, again I've included it here but its the standard file created on setup and unmodified...?
class BootStrap {
def init = { servletContext ->
}
def destroy = {
}
}
Domain code is: -
package test
class PC {
static constraints = {
MyName()
MyVal1()
MyVal2()
}
String MyName
String MyVal1
String MyVal2
}
Java and Groovy naming convention is to start class names uppercase and variables and instances lowercase. To take advantage of Grails convention, it is recommended to follow the same convention as java and groovy. Grails does some magics based on the variable names, for example, Grails matches domain fields to their database fields by their name or Grails bean autowiring is based on bean's name, therefore, creating variables with UpperCase might have confused it in your case.
Background
I am evaluating Grails and thus have to map the persistence layer for a legacy database. I am starting with three tables:
Clone
among other attributes: primary key id
CloneSet
among other attributes: primary key id
Clone2CloneSet
just two foreign keys cloneID and cloneSetID
The domain classes are coded as follows:
class Clone {
// among others
static hasMany = [cloneSets: CloneSet]
static mapping = {
id (generator: 'identity')
cloneSets (
joinTable: [name: 'Clone2CloneSet', key: 'cloneID', column: 'cloneSetID'],
cascade: 'none'
)
}
}
class CloneSet {
// among others
static hasMany = [clones: Clone]
static belongsTo = Clone
static mappedBy = [clones: "cloneSets"]
static mapping = {
table (name: 'CloneSet')
id (generator: 'identity')
clones (
joinTable: [name: 'Clone2CloneSet', key: 'cloneSetID', column: 'cloneID'],
cascade: 'none'
)
}
}
Problem
Grails seems to insist that the name of my join table is clone2clone_set:
2013-09-12 10:39:26,459 [localhost-startStop-1] INFO hbm2ddl.TableMetadata - table found: mydatabase.dbo.CloneSet
2013-09-12 10:39:26,459 [localhost-startStop-1] INFO hbm2ddl.TableMetadata - columns: [id, ...]
2013-09-12 10:39:26,465 [localhost-startStop-1] INFO hbm2ddl.TableMetadata - table found: mydatabase.dbo.Clone
2013-09-12 10:39:26,465 [localhost-startStop-1] INFO hbm2ddl.TableMetadata - columns: [id, ...]
2013-09-12 10:39:26,469 [localhost-startStop-1] INFO hbm2ddl.DatabaseMetadata - table not found: clone2clone_set
| Error 2013-09-12 10:39:26,481 [localhost-startStop-1] ERROR context.GrailsContextLoader - Error initializing the application: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.HibernateException: Missing table: clone2clone_set
Message: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.HibernateException: Missing table: clone2clone_set
Line | Method
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 166 | run in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 724 | run . . . in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.HibernateException: Missing table: clone2clone_set
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 166 | run in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 724 | run . . . in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.HibernateException: Missing table: clone2clone_set
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 166 | run in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 724 | run . . . in java.lang.Thread
Caused by HibernateException: Missing table: clone2clone_set
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 166 | run in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 724 | run . . . in java.lang.Thread
Question
How can I persuade Grails to search for the correct join table?
I suppose you do not need mappedBy in CloneSet.
class CloneSet {
static hasMany = [clones: Clone]
static belongsTo = Clone
//Do you really need this?
//This maps to CloneSet which is incorrect
//static mappedBy = [clones: "cloneSets"]
static mapping = {
table name: 'CloneSet'
id generator: 'identity'
clones joinTable: [name: 'Clone2CloneSet', key: 'cloneSetID',
column: 'cloneID'],
cascade: 'none'
}
}
Moreover, if feasible can table names become CLONE_SET, CLONE_CLONE_SET (or CLONE_CLONE_SET_XREF for cross reference). Grails uses CamelCase for domain names and table are named as Camel_Case.
In my case it worked with setting the table name to clone2cloneset, because SQL Server isn't case-sensitive. (This has to be done for all column names as well: no camel-case notation there.)
Grails 2.0.4 - Using dynamic scaffolding with a inlist constraint and dynamic finders.
I am trying to use a dynamic finder in the inList constraint of a domain object.
If I change the constraint while the application is active via run-app to sample 2 = Aidy.findAll()*.code it works beautifully creating the dropdown on the objects form from the bootstrapped sample data.
However, subsequent bootstrapping of the application using grails run-app fails with a MissingMethodException.
//1- aidyear(blank:false, maxSize:4, inList:{ [] << '0203' << '0304' << '0405' << '0506'}())
//2- aidyear(blank:false, maxSize:4, inList:{ Aidy.findAll()*.code}())
Is using the findAll in a domain's inlist constraint a bad idea? Any suggestions/recommendations?
The abbreviated error is
$ grails run-app
| Running Grails application
| Error 2012-11-09 12:54:16,589 [pool-5-thread-1] ERROR context.GrailsContextLoader - Error executing bootstraps: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: edu.uvm.Aidy.findAll() is applicable for argument types: () values: []
Possible solutions: findAll(), findAll(), findAll(groovy.lang.Closure), findAll(java.lang.Object), findAll(java.lang.String), findAll(groovy.lang.Closure)
Message: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: edu.uvm.Aidy.findAll() is applicable for argument types: () values: []
Possible solutions: findAll(), findAll(), findAll(groovy.lang.Closure), findAll(java.lang.Object), findAll(java.lang.String), findAll(groovy.lang.Closure)
Line | Method
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 138 | run in java.util.concurrent.FutureTask
| 886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
| 908 | run in ''
^ 680 | run . . in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: edu.uvm.Aidy.findAll() is applicable for argument types: () values: []
Possible solutions: findAll(), findAll(), findAll(groovy.lang.Closure), findAll(java.lang.Object), findAll(java.lang.String), findAll(groovy.lang.Closure)
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync
....
....
...
I have a simple example project at: https://github.com/mlmclaug/scaffold_inlist.git
but it is just the following 2 domain objects, a controller, and a bootstrap.groovy
package edu.uvm
class Aidy {
String code
String desc
Date startDate
Date endDate
String statusInd
static constraints = {
code(unique:true,blank:false, maxSize:4)
desc(blank:false, maxSize:30)
startDate(blank:false)
endDate(blank:false)
statusInd(blank:false, inList:["A","I"])
}
}
package edu.uvm
class TreqMap {
String aidyear
String treq
Integer seqno
static constraints = {
aidyear(blank:false, maxSize:4, inList:{ [] << '0203' << '0304' << '0405' << '0506'}())
//aidyear(blank:false, maxSize:4, inList:{ Aidy.findAll()*.code}())
treq(blank:false, maxSize:6, inList:["BNOTE","SCERT","PERKIN","PNOTE","LNOTE","SNOTE"])
seqno(blank:true, range:0..99)
}
}
package edu.uvm
class TreqMapController {
def scaffold = edu.uvm.TreqMap
}
import edu.uvm.Aidy
class BootStrap {
def init = { servletContext ->
new Aidy(code:'0910', desc:'July 2009 - June 2010', startDate:'07/01/2009', endDate:'06/30/2010', statusInd:'A').save(failOnError:true)
new Aidy(code:'1011', desc:'July 2010 - June 2011', startDate:'07/01/2010', endDate:'06/30/2011', statusInd:'A').save(failOnError:true)
new Aidy(code:'1112', desc:'July 2011 - June 2012', startDate:'07/01/2011', endDate:'06/30/2012', statusInd:'A').save(flush:true,failOnError:true)
println "Loaded " + Aidy.count() + " Aid Years"
}
def destroy = {
}
}