Olav Grønås Gjerde

profile image
Full stack system architect with passion for Unix, Java, Python and databases.
Twitter @olavgg
2 months ago

Secure cookie flag for Grails 3

Add this to your application.yml

server:
    servlet:
        session:
            cookie:
                domain: olavgg.com
                http-only: true
                path: /
                secure: true

This should work with Grails 4+ and I have verified that it works with Grails 5

For older Spring versions and Grails 3 this was

server:
    session:
        cookie:
            domain: adminpanel-test-boost.ai
            http-only: true
            path: /
            secure: true
6 months ago

Native hibernate query in Grails

Here is a simple example of how to do a native database query with Hibernate

@Service(Sensor)
abstract class SensorService implements ISensorService {

    SessionFactory sessionFactory

    Sensor findByTag(String tag){
        Session session = sessionFactory.currentSession
        String sql = """
                "select * from sensor where tag = :tag
        """
        Query query = session.createNativeQuery(sql, Sensor)
        query.setParameter("tag", tag)
        return query.getSingleResult()
    }

}

View older blog posts ⇾