简体   繁体   中英

Grails Hibernate Session Read Only

I have two grails servers:

  • Server - has read/write access to the database
  • Web - has read-only access to the database, and for every write it sends a request to the server

The problem: How do I make the Web's domain objects read only in one place (config file) for the entire run of the application, instead of writing caching: 'read-only' for each domain class' mapping.

Para-phrased from http://www.nabble.com/database-read-only-td20360158.html

If you have pooled=true in DataSource.groovy this creates a org.apache.commons.dbcp.BasicDataSource. You can set the defaultReadOnly property in the BootStrap.groovy:

class BootStrap { 

      def dataSource 

      def init = { servletContext -> 
         dataSource.defaultReadOnly = true 
      } 

      def destroy = {} 
} 

with grails 1.3.7

use [dataSourceUnproxied] instead of [dataSource]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM