【发布时间】:2017-02-24 15:22:50
【问题描述】:
更多关于 Groovy/Grails 的初学者问题。
Groovy 2.4.8 版 Grails 2.5.1 版
我尝试了多种方法来序列化我的某个域类的实例或该域类实例的 ArrayList。
在尝试序列化单个实例时,出现堆栈溢出错误。
代码和堆栈跟踪如下所示
def getAdvisors(String keystrokes, String firm) {
def advisors = priceBlotterService.advisorsForKeystrokes(keystrokes, "", 30)
def a1 = advisors[0]
def json = JsonOutput.toJson(a1)
}
Caused by InvocationTargetException: null
->> 198 | doFilter in grails.plugin.cache.web.filter.PageFragmentCachingFilter
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run . . . in java.lang.Thread
Caused by StackOverflowError: null
->> 100 | invoke in org.codehaus.groovy.reflection.CachedMethod
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 62 | getProperty in groovy.lang.MetaBeanProperty
| 42 | getValue in groovy.lang.PropertyValue
| 388 | getProperties in org.codehaus.groovy.runtime.DefaultGroovyMethods
| 290 | writeObject in groovy.json.JsonOutput
| 329 | writeArray in ''
| 286 | writeObject in ''
| 424 | writeMap in ''
| 294 | writeObject in ''
| 329 | writeArray in ''
| 286 | writeObject in ''
| 424 | writeMap in ''
顾问、案例和公司类别:
class Advisor {
String firstName
String lastName
String fullName
String city
String state
Firm firm
static belongsTo = [Case, Firm]
static hasMany = [cases:Case]
static constraints = {
}
}
class Case {
String caseCode
String internalComment
String externalComment
Date dateCreated
String createdBy
Date dateUpdated
String updatedBy
static belongsTo = [owner:User, caseStatusType:CaseStatusType]
static hasMany = [advisor:Advisor]
static mapping = {
dateCreated sqlType: "date"
dateUpdated sqlType: "date"
}
static constraints = {
dateCreated(nullabe: false)
dateUpdated(nullable: false)
}
}
class Firm {
String name
static constraints = {
}
}
编辑:
我发现我的域类/表存在一个基本问题,可能与此有关,需要解决。
我尝试从用户表中进行简单的获取,但我收到一条错误消息,表明没有 id 字段。很难弄清楚发生了什么。一些细节如下。
代码行
User[] users = User.findAll()
错误信息
org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: could not extract ResultSet; bad SQL grammar [n/a]; nested exception is org.postgresql.util.PSQLException: ERROR: column this_.id does not exist Position: 8
用户类
class User {
String firstName
String lastName
static constraints = {
}
}
用户表的ddl
CREATE TABLE "user"
(
id BIGINT DEFAULT nextval('user_id_seq'::regclass) PRIMARY KEY NOT NULL,
first_name VARCHAR(30),
last_name VARCHAR(30),
version BIGINT
);
CREATE UNIQUE INDEX user_id_uindex ON "user" (id);
编辑:
使用用户表/类修复发行者。 User 是 Postresql 中的一个关键字,所以我只是重构为 EndUser。
【问题讨论】:
-
您可以发布您的案例和公司课程的详细信息吗?
-
@LeslieV 好的,谢谢!