title: PostgreSQL/JPA - Import functions in import.sql file?
body: <p>I'm trying to define some PostgreSQL functions and triggers in my JPA <code>import.sql</code> file.  I'm using Hibernate 5.x as my underlying JPA provider.  Since my <code>import.sql</code> file has commands that are multiple lines, I've got this property set in my <code>persistence.xml</code> file:</p>
  
  <pre><code>&lt;property name="hibernate.hbm2ddl.import_files_sql_extractor" value="org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor" /&gt;
  </code></pre>
  
  <p>From there, I'm trying to define my functions in <code>import.sql</code>.  They look something like this:</p>
  
  <pre><code>DROP FUNCTION IF EXISTS update_total_feedback_count() CASCADE;
  CREATE FUNCTION update_total_feedback_count() RETURNS TRIGGER AS
  $$
  DECLARE
    application_version_id BIGINT := 0;
    app_version_metadata_id BIGINT:= 0;
    application_id BIGINT := 0;
    app_metadata_id BIGINT := 0;
  BEGIN
      IF (TG_OP = 'INSERT') THEN
          SELECT INTO application_version_id tbl_application_version.id
              FROM tbl_application_version
              INNER JOIN tbl_feedback ON tbl_feedback.application_version_id = tbl_application_version.id
              WHERE tbl_feedback.id = NEW.id;
  
          SELECT INTO app_version_metadata_id tbl_application_version.application_version_metadata_id
              FROM tbl_application_version
              WHERE id = application_version_id;
  
          SELECT INTO app_metadata_id registered_application_metadata_id
              FROM tbl_registered_application
              INNER JOIN tbl_application_version ON tbl_application_version.registered_application_id = tbl_registered_application.id
              WHERE tbl_application_version.id = application_version_id;
  
          UPDATE tbl_registered_application_metadata SET feedbackcount = (feedbackcount + 1), lastfeedbackdate = NEW.createddate WHERE id = app_metadata_id;
          UPDATE tbl_application_version_metadata SET feedbackcount = (feedbackcount + 1), lastfeedbackdate = NEW.createddate WHERE id = app_version_metadata_id;
  
          RETURN NEW;
      ELSIF (TG_OP = 'DELETE') THEN
          -- IMPLEMENT THIS TRIGGER
  
          RETURN NULL;
      END IF;
  END;
  $$
  LANGUAGE 'plpgsql';
  ALTER FUNCTION update_total_feedback_count() OWNER TO feedback_tracker;
  </code></pre>
  
  <p>However, when I deploy my WAR file, I get an error saying something like this:</p>
  
  <blockquote>
    <p>Unterminated dollar quote started at position 65 in SQL CREATE
    FUNCTION my_function() RETURNS TRIGGER AS $$</p>
  </blockquote>
  
  <p>So, clearly it's dying on the <code>$$</code> in my function declaration.  Is there a way around this?  Should I be declaring my function/trigger differently?  Is there a property I can set in my <code>persistence.xml</code> file that will get around this?</p>