These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: org.hibernate.exception.SQLGrammarException: could not execu
PostPosted: Sun Jan 22, 2006 7:18 am 
Newbie

Joined: Thu Nov 24, 2005 8:17 am
Posts: 10
Hi Everyone,
Everything was goin smoothly ,then suddenly this happened and i dont know wats the problem.

When I try to run a QUERY by givn a where clause ,It throws me an error

I have a field in teh table called CODE_NAME and is a composite key.
now when i say ("FROM codeMaster where codeName='dummy'")

It generates a wrong SQL
SELELCT <<FIELDS>> FROM CODE_MASTER WHERE codeName='DUMMY'

but actually the table coulmn name is CODE_NAME

my Mapping Files is

<hibernate-mapping package="org.helpdesk.util">

<class name="CodeMaster" table="Code_Master">
<composite-id name="id" class="CodeMasterKey">
<key-property name="codeName" column="Code_Name" type="string"/>
<key-property name="codeValue" column="Code_Value" type="string"/>
</composite-id>

<property name="codeDesc" column="Code_Desc" type="string" />
<property name="codeStatus" column="Code_Status" type="string" />
</class>

</hibernate-mapping>



My Code Is

session = factory.openSession();
tx = session.beginTransaction();
Query getStatus= session.createQuery("From CodeMaster WHERE codeName=DUMMY");




My Javabean is
package org.helpdesk.util;

import java.io.Serializable;

/**
* A class that represents a row in the 'Code_Master' table.
* This class may be customized as it is never re-generated
* after being created.
*/
public class CodeMaster
implements Serializable
{
/**
* Simple constructor of CodeMaster instances.
*/
public CodeMaster()
{
}



/* Add customized code below */
/** The cached hash code value for this instance. Settting to 0 triggers re-calculation. */
private int hashValue = 0;

/** The simple primary key value. */
private CodeMasterKey id;

/** The value of the simple codeDesc property. */
private java.lang.String codeDesc;

/** The value of the simple codeStatus property. */
private java.lang.String codeStatus;

/**
* Constructor of CodeMaster instances given a composite primary key.
* @param id
*/
public CodeMaster(CodeMasterKey id)
{
setId(id);
}
/**
* Return the composite id instance that identifies this object.
* @return CodeMasterKey
*/
public CodeMasterKey getId()
{
return this.id;
}

/**
* Set the composite id instance that identifies this object.
* @param id
*/
public void setId(CodeMasterKey id)
{
this.hashValue = 0;
this.id = id;
}

/**
* Return the value of the Code_Desc column.
* @return java.lang.String
*/
public java.lang.String getCodeDesc()
{
return this.codeDesc;
}

/**
* Set the value of the Code_Desc column.
* @param codeDesc
*/
public void setCodeDesc(java.lang.String codeDesc)
{
this.codeDesc = codeDesc;
}

/**
* Return the value of the Code_Status column.
* @return java.lang.String
*/
public java.lang.String getCodeStatus()
{
return this.codeStatus;
}

/**
* Set the value of the Code_Status column.
* @param codeStatus
*/
public void setCodeStatus(java.lang.String codeStatus)
{
this.codeStatus = codeStatus;
}

/**
* Implementation of the equals comparison on the basis of equality of the primary key values.
* @param rhs
* @return boolean
*/
public boolean equals(Object rhs)
{
if (rhs == null)
return false;
if (! (rhs instanceof CodeMaster))
return false;
CodeMaster that = (CodeMaster) rhs;
if (this.getId() == null || that.getId() == null)
return false;
return (this.getId().equals(that.getId()));
}

public int hashCode()
{
if (this.hashValue == 0)
{
int result = 17;
if (this.getId() == null)
{
result = super.hashCode();
}
else
{
result = this.getId().hashCode();
}
this.hashValue = result;
}
return this.hashValue;
}
}


and my Key class is


import java.io.Serializable;

public class CodeMasterKey
implements Serializable
{

private volatile int hashValue = 0;

/** The value of the Code_Name component of this composite id. */
private java.lang.String codeName;

/** The value of the Code_Value component of this composite id. */
private java.lang.String codeValue;

/**
* Simple constructor of CodeMasterKey instances.
*/
public CodeMasterKey()
{
}

/**
* Returns the value of the codeName property.
* @return java.lang.String
*/
public java.lang.String getCodeName()
{
return codeName;
}

/**
* Sets the value of the codeName property.
* @param codeName
*/
public void setCodeName(java.lang.String codeName)
{
hashValue = 0;
this.codeName = codeName;
}

/**
* Returns the value of the codeValue property.
* @return java.lang.String
*/
public java.lang.String getCodeValue()
{
return codeValue;
}

/**
* Sets the value of the codeValue property.
* @param codeValue
*/
public void setCodeValue(java.lang.String codeValue)
{
hashValue = 0;
this.codeValue = codeValue;
}

/**
* Implementation of the equals comparison on the basis of equality of the id components.
* @param rhs
* @return boolean
*/
public boolean equals(Object rhs)
{
if (rhs == null)
return false;
if (! (rhs instanceof CodeMasterKey))
return false;
CodeMasterKey that = (CodeMasterKey) rhs;
if (this.getCodeName() == null || that.getCodeName() == null)
{
return false;
}
if (! this.getCodeName().equals(that.getCodeName()))
{
return false;
}
if (this.getCodeValue() == null || that.getCodeValue() == null)
{
return false;
}
if (! this.getCodeValue().equals(that.getCodeValue()))
{
return false;
}
return true;
}

public int hashCode()
{
if (this.hashValue == 0)
{
int result = 17;
int codeNameValue = this.getCodeName() == null ? 0 : this.getCodeName().hashCode();
result = result * 37 + codeNameValue;
int codeValueValue = this.getCodeValue() == null ? 0 : this.getCodeValue().hashCode();
result = result * 37 + codeValueValue;
this.hashValue = result;
}
return this.hashValue;
}
}


Please help me out

Thanks a Lot in Advance

Askari


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 22, 2006 10:58 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
CodeMaster does not have a mapped property named 'codeName' at all actually, so Hibernate simply passes that vlue through to the database.

What you really want is something like :
Code:
from CodeMaster cm
where cm.id.codeName='DUMMY'


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.