GoZ GoZ - 1 year ago 74
Java Question

Error in SQL Syntax using hibernate

I'm trying to use an hibernate query doing


my query contains

from com.classes.Project where NAME='test'

But I get an error :

You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near '.project project0_ where NAME='test'' at line 1

The full query generated by hibernate is :

select project0_.PROJECT_ID as PROJECT1_60_, project0_.CL_ID as
CL2_60_, project0_.ATTACHMENT_LIST_ID as ATTACHMENT3_60_,
project0_.TCL_ID as TCL4_60_, project0_.RL_ID as RL5_60_,
project0_.NAME as NAME60_, project0_.DESCRIPTION as DESCRIPT7_60_,
project0_.LABEL as LABEL60_, project0_.ACTIVE as ACTIVE60_,
project0_.CREATED_BY as CREATED10_60_, project0_.CREATED_ON as
CREATED11_60_, project0_.LAST_MODIFIED_BY as LAST12_60_,
project0_.LAST_MODIFIED_ON as LAST13_60_, project0_.PROJECT_TYPE as
PROJECT14_60_, project0_.TA_SERVER_ID as TA15_60_ from
squashtmdev.squashtm.project project0_ where NAME='test'

Associated mapping :

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
<!-- Generated 2 ao?t 2016 14:54:16 by Hibernate Tools 3.4.0.CR1 -->
<class name="com.classes.Project" table="project" catalog="squashtmdev">
<id name="projectId" type="java.lang.Long">
<column name="PROJECT_ID" />
<generator class="identity" />
<many-to-one name="campaignLibrary" class="com.classes.CampaignLibrary" fetch="select">
<column name="CL_ID" />
<many-to-one name="attachmentList" class="com.classes.AttachmentList" fetch="select">
<column name="ATTACHMENT_LIST_ID" not-null="true" />
<many-to-one name="testCaseLibrary" class="com.classes.TestCaseLibrary" fetch="select">
<column name="TCL_ID" />
<many-to-one name="requirementLibrary" class="com.classes.RequirementLibrary" fetch="select">
<column name="RL_ID" />
<property name="name" type="string">
<column name="NAME" not-null="true" />
<property name="description" type="string">
<column name="DESCRIPTION" />
<property name="label" type="string">
<column name="LABEL" />
<property name="active" type="boolean">
<column name="ACTIVE" not-null="true" />
<property name="createdBy" type="string">
<column name="CREATED_BY" length="50" not-null="true" />
<property name="createdOn" type="timestamp">
<column name="CREATED_ON" length="19" not-null="true" />
<property name="lastModifiedBy" type="string">
<column name="LAST_MODIFIED_BY" length="50" />
<property name="lastModifiedOn" type="timestamp">
<column name="LAST_MODIFIED_ON" length="19" />
<property name="projectType" type="char">
<column name="PROJECT_TYPE" length="1" not-null="true" />
<property name="taServerId" type="java.lang.Long">
<column name="TA_SERVER_ID" />
<set name="testCaseLibraryNodes" table="test_case_library_node" inverse="true" lazy="true" fetch="select">
<column name="PROJECT_ID" />
<one-to-many class="com.classes.TestCaseLibraryNode" />
<set name="campaignLibraryNodes" table="campaign_library_node" inverse="true" lazy="true" fetch="select">
<column name="PROJECT_ID" />
<one-to-many class="com.classes.CampaignLibraryNode" />
<set name="projectFilterEntries" table="project_filter_entry" inverse="true" lazy="true" fetch="select">
<column name="PROJECT_ID" not-null="true" />
<one-to-many class="com.classes.ProjectFilterEntry" />
<set name="requirementLibraryNodes" table="requirement_library_node" inverse="true" lazy="true" fetch="select">
<column name="PROJECT_ID" />
<one-to-many class="com.classes.RequirementLibraryNode" />

Any ideas why this is happening ?

Answer Source

This is how I fixed my problem :

1 - Remove the catalog on the hbm files by using the hibernate.default_catalog property in the configuration file and regenerating the classes.

2 - Then if it didn't work and the error is now could not find the table yourDatabase.yourTable or using HQL editor yourDatabase.yourTable is not mapped try to remove the table="yourTable" in the concerned hbm file

I'am not sure about why I had to do that, I hope it will help

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download