Grails: display column names of a field and attribute of the same type

I am trying to match the column names of this class:

class Amount{ String total //Total amount of something String type //Type of amount, Dollars, %, Times something Bonification bonificationRate //the amount can be "x times another bonification" static belongsTo = [parentBonification: Bonification] static mapping = { table "AMOUNTS" total column: "AMOU_TTOTAL" type column: "AMOU_TTYPE" parentBonification column: "BONI_CID" bonificationRate column: "BONI_TRATE_CID" } } class Bonification { //among other things: Amount amount } 

The fact is that not a single field with the Bonification class is created in the database, and not with the name that I give it, and with the names that were selected by default.

Editing comments:

  • Both are domain classes;
  • The data source is at dbCreate = "update"
  • I dropped the table in Oracle and let Grails create it again. Bonification columns are still missing.
  • I can’t dbCreate = "create-drop" because there is data that I can’t delete right now.
  • I installed a new local Derby database with dbCreate = create-drop . Still out of luck.

(PD: all other fields are saved and displayed with the names of the right column, only those two Bonification fields)
Is there any other way to do this?

Grails: 1.3.9
BD: Oracle 9

Edit for the specified DataSource.groovy (External file is available from Config.groovy grails.config.locations = [ "file:${extConfig}/${appName}Config.groovy"] )

 package xx.xxx.xxxx.xxxXxxx dataSource { pooled = true dialect = "org.hibernate.dialect.Oracle10gDialect" driverClassName = "oracle.jdbc.OracleDriver" username = "XXX" password = "XXX" properties { maxActive = 100 maxIdle = 25 minIdle = 5 initialSize = 5 minEvictableIdleTimeMillis = 60000 timeBetweenEvictionRunsMillis = 60000 maxWait = 10000 validationQuery = "select 1 from dual" } } hibernate { cache.use_second_level_cache = true cache.use_query_cache = true cache.provider_class = 'net.sf.ehcache.hibernate.EhCacheProvider' } // environment specific settings environments { development { println "Including external DataSource" dataSource { dbCreate = "update" url = "jdbc:oracle:thin:@xxx.xxx.xx:xxxx:XXXX" } } } 
+4
source share
1 answer

Ok, finally, I get it.

I used the mappedBy property.

http://grails.org/doc/2.1.0/ref/Domain%20Classes/mappedBy.html

The documentation ( 6.2.1.2 "One-to-Many") says that for use on the side is "hasMany". This confused me because I did not have hasMany, but just two fields of the same type in Class Amount . And I really needed to use the mappedBy property, not in the sum class, but in the Bonification class, which has only one reference to Amount .

And with this I tell the Amount Class , in which Bonification it should refer to the link, so "it" is not confused and takes the bonificationRate field as a field, and not as a link, as I think it did it before.

 class Amount{ String total //Total amount of something String type //Type of amount, Dollars, %, Times something Bonification bonificationRate //the amount can be "x times another bonification" static belongsTo = [parentBonification: Bonification] static mapping = { table "AMOUNTS" total column: "AMOU_TTOTAL" type column: "AMOU_TTYPE" parentBonification column: "BONI_CID" bonificationRate column: "BONI_TRATE_CID" } } class Bonification { //among other things: Amount amount static mappedBy = [amount: "parentBonification"] } 

This did not create the parentBonification "BONI_CID" column , but it created the bonificationRate "BONI_TRATE_CID" that I needed.

Sorry if this is too dirty. Thanks for the time and help anyway.

+3
source

All Articles