I am currently trying to create a new Grails application based on a legacy MySQL database. The application should only read information. The concrete DB schema uses for the specific domain classes a table per class hierarchy structure, as well as a property class to add new needed information to these classes.
Currently I cannot retrieve the property information for a transation. There is no exception, but I also cannot access the field properties. One problem I may face is, that the word properties is a keyword for Grails for the domain fields. But I need to use it because of the specific legacy table naming.
The legacy tables are named transaction and transaction_properties. One transcation can have muliple transaction_properties. The association is done via the key transaction_id in the transaction_properties table.
Table transaction
id bigint(20)
transaction_id varchar(255) (bad naming here, transaction_id is used to store additional meta information)
Table transaction_properties
transaction_id bigint(20) -> referencing to transation.id
property_value varchar(255)
property_key varchar(32)
etc.
Domain class Transaction
class Transaction {
static hasMany = [properties : TransactionProperty]
static constraints = {
// transactionProperty unique: true
}
static mapping = {
table "transaction"
version false
columns {
id column : "id"
beginDate column : "start"
endDate column : "end"
type column : "DTYPE"
amount column : "total_amount"
metaId column : "transaction_id"
purchase column : "purchase_id"
service column : "service_id"
origin column : "origin_id"
properties column : "id"
}
}
Long id
Date beginDate
Date endDate
String type
String amount
String metaId
Purchase purchase
Origin origin
Service service
etc.
}
Domain class TransactionProperty
class TransactionProperty {
static mapping = {
table "transaction_properties"
version false
columns {
id name : "transaction_id"
key column : "property_key"
value column : "property_value"
}
}
String value
String key
Long id
def asString(){
return "${key} = ${value}"
}
}
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'kt-testing.transaction_transaction_properties' doesn't exist- user1829893