-->
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.  [ 3 posts ] 
Author Message
 Post subject: "select * from __table" instead of "select *
PostPosted: Tue Apr 12, 2005 8:02 pm 
Senior
Senior

Joined: Tue Jan 11, 2005 5:03 pm
Posts: 137
Location: Montreal, Quebec
Hi,

I have a strange problem with Hibernate when it generate the SQL. I am trying to use the Spring framework to set the Connection Factory, the session etc. But it doesn't seems to be a Spring problem, the only thing it could be would be a conflict between "commons" librairies. The Spring framework has correctly instantiated all the beans for Hibernate, but when Hibernate tries to make a very simple SQL (from a very simple HQL) it put 2 understores in front of the table name!

I have generated the job.hbm.xml using the Artifact Generator :

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<!--
   Auto-generated mapping file from
   the hibernate.org cfg2hbm engine
-->

<!-- JOB TABLE HERE --------------------------------- -->
<class
    name="com.etl.persistence.model.Job"
    table="job"
    catalog=""
>
   <id
        name="Id"
        type="java.lang.Integer"
    >
       <column name="id" length="10" not-null="true" sql-type="int unsigned" />
       <generator class="assigned" />
    </id>
   
    <property
        name="Date"
        type="java.util.Date"
    >
        <column name="date" length="19" not-null="true" sql-type="datetime" />
   </property>

    <property
        name="Type"
        type="java.lang.String"
    >
        <column name="type" not-null="true" sql-type="varchar" />
   </property>

   <set
      name="SetOfLoad"
      >
      <key>
                        <column name="jobId" length="10" not-null="false" unique="true" />
                 </key>
               <one-to-many
          class="com.etl.persistence.model.Load"
         />
         </set>
</class>
</hibernate-mapping>



So, as you can see, my classe com.etl.persistence.model.Job is linked to the table job.

This is the code for the Dao, I am using the AOP Interceptor as described in chapter 11.2.4 of the Spring Reference Documentation. The only thing I changed from the exemple is passing a true parameter in getSession instead of false parameter (create session if session==null).

Code:
package com.etl.persistence.dao;

import java.util.List;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.SessionFactoryUtils;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class JobDaoImpl extends HibernateDaoSupport implements IJobDao{

   public List listAllJob(){
         Session session = SessionFactoryUtils.getSession(getSessionFactory(), true);
         List result = session.createQuery("from Job as job").list();
         return result;
      }
}


And here's my test:

Code:
package com.desjardins.vmd.etl.persistence.dao;

import java.util.List;

import junit.framework.TestCase;
import com.desjardins.vmd.util.SpringUtil;

public class JobDaoTest extends TestCase {
   /**
    * Constructor for ConfigurationReaderTest.
    * @param arg0
    */
   public JobDaoTest(String arg0) {
      super(arg0);
   }
   
   public void testListAllJob() {
      JobDaoImpl job = SpringUtil.getJobDao();
      List l = job.listAllJob();
      assertNotNull(l);
      assertEquals(4, l.size());
      
   }

}



The problem is linked to the SQL generation :
Code:
INFO: SQLErrorCodes loaded: [DB2, HSQL, MS-SQL, MySQL, Oracle, Informix, PostgreSQL, Sybase]
12-Apr-2005 7:36:55 PM org.springframework.beans.factory.support.AbstractBeanFactory getBean
INFO: Creating shared instance of singleton bean 'jobDaoTarget'
12-Apr-2005 7:36:55 PM org.springframework.beans.factory.support.AbstractBeanFactory getBean
INFO: Creating shared instance of singleton bean 'myJobDao'
12-Apr-2005 7:36:55 PM org.springframework.aop.framework.DefaultAopProxyFactory <clinit>
INFO: CGLIB2 available: proxyTargetClass feature enabled
12-Apr-2005 7:36:55 PM org.springframework.aop.framework.ProxyFactoryBean createAdvisorChain
INFO: Bean with name 'jobDaoTarget' concluding interceptor chain is not an advisor class: treating it as a target or TargetSource
12-Apr-2005 7:36:55 PM org.springframework.beans.factory.support.AbstractBeanFactory getBean
INFO: Creating shared instance of singleton bean 'jndiTemplate'
<!-- WRONG SQL HERE! --------------------------------- -->
Hibernate: select job0_.id as id, job0_.date as date1_, job0_.type as type1_ from __job job0_
<!-- WRONG SQL HERE! --------------------------------- -->
12-Apr-2005 7:36:56 PM org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 1146, SQLState: 42S02
12-Apr-2005 7:36:56 PM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: Table 'etl.__job' doesn't exist


The table name should be job instead of __job!

Any idea? I will continu working on that... maybe Spring is interfering with Hibernate?

Thanks for any clue.
Etienne
Montreal


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 13, 2005 7:03 am 
Regular
Regular

Joined: Wed Feb 02, 2005 6:33 am
Posts: 70
In your mapping,

Code:
catalog=""


remove the catalog line. By defualt, if catalog is specified, then hibernate will generate the table name

{catalog}_{schema}_{tablename}

or something similar. Since your catalog is the empty string, and no schema is specified, you just get

__{tablename}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 13, 2005 8:52 am 
Senior
Senior

Joined: Tue Jan 11, 2005 5:03 pm
Posts: 137
Location: Montreal, Quebec
Thanks a lot it works! I see that the Artifact Generator (alpha or Beta version) does not generate ready-to-go hbm... we have to do some manual correction on it.

Etienne.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.