0

I need to add a new datasource to my grails project wich uses the musicbrainz postgresql database. http://musicbrainz.org/doc/MusicBrainz_Database

I found a project on github where the data bindings are ready to use for a spring project: https://github.com/lastfm/musicbrainz-data

Am i able to use these data bindings in a grails 2.2.3 project? If yes, how can i do this? (because there is no hibernate xml as needed by grails (regarding to the grails documentation: Hibernate Mapped Domain Classes))

whitenexx
  • 1,350
  • 2
  • 25
  • 53
  • 2
    Are you asking this because there is some reason you don't want to use GORM domain objects? – BoxerBucks Aug 18 '13 at 19:24
  • I'm not sure. I have an existing grails project with database and domain classes. Now i want to access to another database (musicbrainz) to get information from there. I thought it would be easier to use the github musicbrainz-data project to access to this data. Isn't it? What would you suggest? (I need every artist and his albums and tracks from the musicbrainz db) – whitenexx Aug 18 '13 at 19:33

1 Answers1

2

I don't think it will be. Just setup the additional datasource and model out the tables or objects you need.

How do you access two databases in Grails

Once you do that, you can use all of the GORM methods and dynamic finders to get your data. Plus validation criteria, transactions, etc. Unless there is some very specialized criteria that make it necessary to bypass GORM, I would suggest leveraging it.

Community
  • 1
  • 1
BoxerBucks
  • 3,124
  • 2
  • 21
  • 26
  • Great comment! I already have a domain class called "Artist" in my project. The musicbrainz database also has a table called "artist" and holds artists. I would like to connect my internal artists with the musicbrainz artists because my internal artists hold some extra information. I already declared multiple datasources (working). Is it possible to define ONE Artist model and declare for each attribute where it comes from? (name from internal datasource, birthdate from musicbrainz datasource and so on). Is this possible? I couldn't find such a thing in the grails documentation. – whitenexx Aug 18 '13 at 20:18
  • Yes, you can. I haven't but the docs discuss it here: http://grails.org/doc/latest/guide/conf.html#multipleDatasources. Look under 'Configuring Domain Classes'. – BoxerBucks Aug 18 '13 at 20:25
  • Thanks. I have to find out what happens. I think grails creates a schema for all attributes in your default datasource and when you query for data you have to decide wich datasource to query. And because i know that the "birthdate" isn't in the default datasource (there is a column/attribute, but it's empty), i have to query the musicbrainz datasource. I hope my "thinking" is correct. – whitenexx Aug 18 '13 at 20:29
  • 1
    Hmm. Maybe you can import one into the other then have a method on your object that fetches the other attributes you need and adds them on dynamically? I'd have to mess with it though. – BoxerBucks Aug 18 '13 at 20:36
  • Good idea! I could use my internal Artist model wich holds the musicbrainz GID of the same artist. Then i write some getters and setters wich get the data from the musicbrainz datasource. Or even better: I create a relation between my internal Artist and the musicbrainz Artist. I could access then via internalArtist.mbArtist.attribute if i need some and gorm would make all querys for me – whitenexx Aug 18 '13 at 21:10
  • I got it working with the relation between internal and musicbrainz Artist. I had to create some getters and setters with subqueries, because you can't create relations between two datasources with hibernate. – whitenexx Aug 19 '13 at 09:22
  • Great! Good luck with the rest of your app. – BoxerBucks Aug 19 '13 at 13:00