Tuesday, September 25, 2012

Grails -Error- expected "identifier"; SQL statement: insert into XYZ Table

Syntax error in SQL statement "INSERT INTO ORDER[*] (ID, VERSION, ADDRESS_ID, NAME, SHIPPING_DATE, USER_ID) VALUES (NULL, ?, ?, ?, ?, ?) "; expected "identifier"; SQL statement: insert into order (id, version, address_id, name, shipping_date, user_id) values (null, ?, ?, ?, ?, ?) [42001-164]


This error shows up when you are using any keyword of database you are using in your Grails app.

I was using the Order Domain class and H2 database . i need to modify the class to avoid this error.


class Order implements java.io.Serializable{

    String name
    String shippingDate
    Address address
    User user
    static mapping = { table 'my_order' }
    static constraints = {
        name(nullable:true,blank:false)
        shippingDate(nullable:true,blank:false)
        address(nullable:true,blank:false)
        user(nullable:true,blank:false)
    }
}

Sunday, April 22, 2012

Grails Domain - ERROR hbm2ddl.SchemaExport - Unsuccessful: create table


| Error 2012-04-22 14:08:00,733 [Thread-8] ERROR hbm2ddl.SchemaExport  - Unsuccessful: create table education (id bigint not null, version bigint not null, field_of_study varchar(255) not null, from timestamp not null, grade varchar(255) not null, school_name varchar(255) not null, to timestamp, primary key (id))
| Error 2012-04-22 14:08:00,733 [Thread-8] ERROR hbm2ddl.SchemaExport  - Syntax error in SQL statement "CREATE TABLE EDUCATION (ID BIGINT NOT NULL, VERSION BIGINT NOT NULL, FIELD_OF_STUDY VARCHAR(255) NOT NULL, FROM[*] TIMESTAMP NOT NULL, GRADE VARCHAR(255) NOT NULL, SCHOOL_NAME VARCHAR(255) NOT NULL, TO TIMESTAMP, PRIMARY KEY (ID)) "; expected "identifier"; SQL statement:
create table education (id bigint not null, version bigint not null, field_of_study varchar(255) not null, from timestamp not null, grade varchar(255) not null, school_name varchar(255) not null, to timestamp, primary key (id)) [42001-147]
| Error 2012-04-22 14:08:00,905 [Thread-8] ERROR hbm2ddl.SchemaExport  - Unsuccessful: alter table my_edu_profile_education add constraint FKC6EB61F6B358A0A4 foreign key (education_id) references education
| Error 2012-04-22 14:08:00,921 [Thread-8] ERROR hbm2ddl.SchemaExport  - Table "EDUCATION" not found; SQL statement:
alter table my_edu_profile_education add constraint FKC6EB61F6B358A0A4 foreign key (education_id) references education [42102-147]


This error comes when you are using one of the keywords from the SQL in your domain class , for example, i was using From and To for one domain class for dates and it was not able to create tables .

Happy Coding
Kulveer Singh

Friday, April 13, 2012

How to configure Apache and Tomcat for Grails applications?

There are two parts to understand here 
1- Apache frontend static content serving server
2- Tomcat for dynamic request processing like jps,jsf,grails,spring framework


We need to configure two things here.
Lets assume that you have apache running on your maching and you just want to configure it for tomcat connectivity .


Find httpd.conf  and configure the below settings and change the mydomain1 and mydomain2 by your actual domain . please make you have the right path for example - /var/log/apach2/error-domain1.log , if you have other path , than configure that one.

ProxyRequests Off

  ErrorLog /var/log/apache2/error-domain1.log

  <Directory proxy:http://www.mydomain1.com:80>
        Order Allow,Deny
        Allow from all
  </Directory>

  <Proxy www.mydomain1.com:80>
    Order deny,allow
    Allow from all
  </Proxy>
  ProxyPass / http://localhost:8082/
  ProxyPassReverse / http://localhost:8082/
  ProxyPreserveHost On
</VirtualHost>

<VirtualHost *:80>
  ServerName www.mydomain2.com
  ServerAlias www.mydomain2.com

  ProxyRequests Off

  ErrorLog /var/log/apache/error-domain2.log

  <Directory proxy:http://www.mydomain12.com:80>
        Order Allow,Deny
        Allow from all
  </Directory>

  <Proxy www.mydomain2.com:80>
    Order deny,allow
    Allow from all
  </Proxy>
  ProxyPass / http://localhost:8084/
  ProxyPassReverse / http://localhost:8084/
  ProxyPreserveHost On
</VirtualHost>

Configure the server.xml in Tomcat . Add these values or if they are there ,just configure them.




<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
    maxThreads="250" minSpareThreads="40"/>




<Connector port="8083" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8444"
           executor="tomcatThreadPool"
           proxyName="www.mydomain1.com"
           proxyPort="80"/>
<Connector port="8084" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8445"
           executor="tomcatThreadPool"
           proxyName="www.mydomain2.com"
           proxyPort="80"/>


  <Host name="www.mydomain1.com" appBase="vhosts/mydomain1" unpackWARs="true"
        autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
            <Alias>mydomain1.com</Alias>
  </Host>
  <Host name="www.mydomain2.com" appBase="vhosts/mydomain2" unpackWARs="true"
        autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
            <Alias>mydomain2.com</Alias>
  </Host>