title: Hibernate java.sql.SQLException: Invalid column name
body: <p>I'm not very experienced on Hibernate and I'm facing a Invalid column name problem with Hibernate for a quite while now.
  I'm just trying to select data from a database using Criteria API, as follow:</p>
  
  <pre><code>public Subject lookupByID(SubjectValue subjectValue) {
      List list;
      Iterator it;
      Criteria criteria = getBaseCriteria();
      criteria = criteria.add(Restrictions.eq("subjectId", subjectValue.getSubjectId()));
      list = criteria.list();
      it = list.iterator();
      if(it.hasNext()){
          return (Subject)it.next();
      }
      else{
          return null;
      }
  }
  </code></pre>
  
  <p>I enabled the Hibernate debug mode and now I can see the select that it generates:</p>
  
  <pre><code>Hibernate: select this_.Subject_id as Subject1_11_0_, this_.Site_id as Site2_11_0_, this_.Notification_id as Notifica3_11_0_, this_.Name as Name11_0_, this_.Description as Descript5_11_0_, this_.UserName as UserName11_0_, this_.DisplayOrder as DisplayO7_11_0_, this_.InsertDate as InsertDate11_0_, this_.insertedBy_id as insertedBy9_11_0_, this_.UpdateDate as UpdateDate11_0_, this_.updatedBy_id as updatedBy11_11_0_, this_.StatusCode as StatusCode11_0_, this_.Template_id as Template13_11_0_, this_.ForwardMail as Forward14_11_0_, this_.AutoReply as AutoReply11_0_, this_.FromName as FromName11_0_, this_.FromMail as FromMail11_0_, this_.ResponseRequired as Respons18_11_0_ from MYSCHEMA.Subject this_ where this_.Subject_id = ?
  </code></pre>
  
  <p>Running this query directly on the DB it works fine, but on hibernate it is showing a:</p>
  
  <pre><code>org.hibernate.exception.SQLGrammarException: could not execute query
  Caused by: java.sql.SQLException: Invalid column name 'Template_id'.
  </code></pre>
  
  <p>Here is my mapping XML:</p>
  
  <pre><code>&lt;hibernate-mapping&gt;
  &lt;class name="MYPACKAGE.model.Subject" table="Subject" dynamic-update="true" &gt;
      &lt;id name="subjectId" type="integer" column="Subject_id"&gt;
          &lt;generator class="identity" /&gt;
      &lt;/id&gt;
      &lt;property name="siteId" column="Site_id" type="integer" /&gt;
      &lt;property name="notificationId" column="Notification_id" type="integer" not-null="false" /&gt;
      &lt;property name="name" column="Name" type="string" /&gt;
      &lt;property name="description" column="Description" type="string" /&gt;
      &lt;property name="userName" column="UserName" type="string" /&gt;
      &lt;property name="displayOrder" column="DisplayOrder" type="integer" /&gt;
      &lt;property name="insertDate" column="InsertDate" type="timestamp" /&gt;
      &lt;property name="insertedBy_id" column="insertedBy_id" type="integer" /&gt;
      &lt;property name="updateDate" column="UpdateDate" type="timestamp" /&gt;
      &lt;property name="updatedBy_id" column="updatedBy_id" type="integer" /&gt;
      &lt;property name="statusCode" column="StatusCode" type="string" /&gt;
      &lt;property name="templateId" column="Template_id" type="integer" /&gt;
      &lt;property name="forwardMail" column="ForwardMail" type="string" /&gt;
      &lt;property name="autoReply" column="AutoReply" type="boolean" /&gt;
      &lt;property name="fromName" column="FromName" type="string" /&gt;
      &lt;property name="fromMail" column="FromMail" type="string" /&gt;
      &lt;property name="responseRequired" column="ResponseRequired" type="boolean" /&gt;
  
  &lt;/class&gt;
  </code></pre>
  
  <p>
  I'm running on Java 1.5.022, Hibernate 3.26GA and JBOSS 6.0 EAP (Very similar to JBOSS AS7).
  Could anyone please help? If you need any further details please let me know and I'll happy to provide.</p>
  
  <p>Have a nice day!</p>
  
  <p>EDIT:
  Table structure:</p>
  
  <pre><code> CREATE TABLE [ITrInnoFramework].[Subject](
      [Subject_id] [int] IDENTITY(1,1) NOT NULL,
      [Site_id] [int] NOT NULL,
      [Notification_id] [int] NULL,
      [Name] [nvarchar](50) NOT NULL,
      [Description] [nvarchar](1000) NOT NULL,
      [DisplayOrder] [int] NOT NULL,
      [InsertDate] [datetime] NOT NULL,
      [InsertedBy_id] [int] NOT NULL,
      [UpdateDate] [datetime] NOT NULL,
      [UpdatedBy_id] [int] NOT NULL,
      [StatusCode] [char](10) NULL,
      [UserName] [varchar](50) NULL,
      [Template_id] [int] NULL,
      [ForwardMail] [varchar](255) NULL,
      [ResponseRequired] [bit] NULL,
      [AutoReply] [bit] NULL,
      [FromName] [varchar](255) NULL,
      [FromMail] [varchar](255) NULL,
   CONSTRAINT [PK_Subject] PRIMARY KEY CLUSTERED 
  (
      [Site_id] ASC,
      [Name] ASC
  )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY],
   CONSTRAINT [IX_Subject_1] UNIQUE NONCLUSTERED 
  (
      [Subject_id] ASC
  )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
  ) ON [PRIMARY]
  
  GO
  
  SET ANSI_PADDING OFF
  GO
  
  ALTER TABLE [ITrInnoFramework].[Subject]  WITH CHECK ADD  CONSTRAINT [FK_Subject_Notification] FOREIGN KEY([Notification_id])
  REFERENCES [ITrInnoFramework].[Notification] ([Notification_id])
  GO
  
  ALTER TABLE [ITrInnoFramework].[Subject] CHECK CONSTRAINT [FK_Subject_Notification]
  GO
  
  ALTER TABLE [ITrInnoFramework].[Subject]  WITH CHECK ADD  CONSTRAINT [FK_Subject_SiteInfo] FOREIGN KEY([Site_id])
  REFERENCES [ITrInnoFramework].[SiteInfo] ([Site_id])
  GO
  
  ALTER TABLE [ITrInnoFramework].[Subject] CHECK CONSTRAINT [FK_Subject_SiteInfo]
  GO
  
  ALTER TABLE [ITrInnoFramework].[Subject]  WITH CHECK ADD  CONSTRAINT [FK_Subject_StatusLkp] FOREIGN KEY([StatusCode])
  REFERENCES [ITrInnoFramework].[StatusLkp] ([StatusCode])
  GO
  
  ALTER TABLE [ITrInnoFramework].[Subject] CHECK CONSTRAINT [FK_Subject_StatusLkp]
  GO
  
  ALTER TABLE [ITrInnoFramework].[Subject]  WITH CHECK ADD  CONSTRAINT [FK_Subject_Template] FOREIGN KEY([Template_id])
  REFERENCES [ITrInnoFramework].[Template] ([Template_id])
  GO
  
  ALTER TABLE [ITrInnoFramework].[Subject] CHECK CONSTRAINT [FK_Subject_Template]
  GO
  
  ALTER TABLE [ITrInnoFramework].[Subject] ADD  CONSTRAINT [DF_Subject_InsertDate]  DEFAULT (getdate()) FOR [InsertDate]
  GO
  
  ALTER TABLE [ITrInnoFramework].[Subject] ADD  CONSTRAINT [DF_Subject_InsertedBy_id]  DEFAULT ((-1)) FOR [InsertedBy_id]
  GO
  
  ALTER TABLE [ITrInnoFramework].[Subject] ADD  CONSTRAINT [DF_Subject_UpdateDate]  DEFAULT (getdate()) FOR [UpdateDate]
  GO
  
  ALTER TABLE [ITrInnoFramework].[Subject] ADD  CONSTRAINT [DF_Subject_UpdatedBy_id]  DEFAULT ((-1)) FOR [UpdatedBy_id]
  GO
  </code></pre>