Имея ниже конфигурацию Grails: Datasource.
environments {
development {
dataSource {
dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
}
datasource_staging_oracle {
dbCreate = "none"
url = "jdbc:oracle:thin:@//myoraclehost:1521/DBNAME"
driverClassName = "oracle.jdbc.OracleDriver"
username = "username"
password = "password"
}
}
Класс домена:
import org.springframework.integration.Message
class SpringMessage {
static mapping = {
datasource 'staging_oracle'
message type: 'blob', column: 'message_bytes'
createdDate type: Date, column: 'created_date'
}
static constraints = {
}
String messageId
Message<?> message
Date createdDate
}
Внутри контроллера извлечение записей с помощью:
SpringMessage springMessage = SpringMessage.findByMessageId('messsage_id_value')
Вышеприведенная строка завершается с ошибкой ниже: Метод класса [com.foo.bar.SpringMessage] использовался вне приложения Grails. При запуске в контексте теста с использованием API-интерфейса имитации или правильной начальной загрузки Grails.
Как это решить? Поиск в Google показывает сообщения, связанные с "тестом" Grails. Но это не тестовый код. Приведенный выше метод findBy вызывается из контроллера Grails. Я использую Grails 2.3.3 и, к сожалению, пока не могу обновиться до последней версии Grails.
ОБНОВЛЕНИЕ
Код контроллера:
class FooController {
def index() {
foo2()
}
private def foo2() {
SpringMessage springMessage = SpringMessage.findByMessageId('my_message_id') //This line blowsup
if ( springMessage) {
println springMessage.createdDate
} else {
println "not found"
}
}
}
Я получаю доступ к контроллеру, используя http://localhost:8080/myapp/foo/index
ОБНОВЛЕНИЕ
Неверное объявление столбца больших двоичных объектов в исходном вопросе. Правильная версия ниже:
class SpringMessage {
static mapping = {
datasource 'staging_oracle'
message type: 'blob', column: 'message_bytes'
createdDate type: Date, column: 'created_date'
}
static constraints = {
}
String messageId
Blob message
Date createdDate
}