-->
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: SQLGrammarException : Base table or view not found
PostPosted: Wed Mar 30, 2005 6:32 am 
Beginner
Beginner

Joined: Wed Mar 30, 2005 5:41 am
Posts: 40
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.0

Mapping documents:
===========
hibernate.cfg.xml :
----------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/babadmin</property>
<property name="hibernate.cglib.use_reflection_optimizer">true</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.show_sql">true</property>
<mapping resource="hibernate/test/Vacation.hbm.xml"/>
</session-factory>
</hibernate-configuration>
===========

===========
Vacation.hbm.xml :
----------------------
<?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
-->
<class name="hibernate.test.Vacation" table="vacation"
catalog="babadmin">
<id name="VacationId" type="java.lang.Integer">
<column name="vacationId" length="11" not-null="true"
unique="true" sql-type="int" />
<generator class="assigned" />
</id>

<property name="StartDate" type="java.util.Date">
<column name="startDate" length="10" not-null="true"
sql-type="date" />
</property>

<property name="EndDate" type="java.util.Date">
<column name="endDate" length="10" not-null="true"
sql-type="date" />
</property>

<property name="Year" type="java.lang.Integer">
<column name="year" length="11" not-null="true"
sql-type="int" />
</property>

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

<property name="Kei" type="java.lang.String">
<column name="kei" length="100" not-null="true"
sql-type="varchar" />
</property>

</class>
</hibernate-mapping>
===========


Code between sessionFactory.openSession() and session.close():
Session session = HibernateUtil.currentSession();
Transaction tx = session.beginTransaction();

try
{
List list = session.createQuery("from Vacation").list();
Iterator it = list.iterator();
while(it.hasNext())
{
Speciality speciality = (Speciality)it.next();
System.out.println(speciality.getContent());
}
}
catch ( SQLGrammarException e )
{
System.out.println( "ERROR" );
System.out.println( e.getMessage() );
System.out.println( e.getSQL() );
System.out.println( e.getSQLException() );
e.printStackTrace();
}
HibernateUtil.closeSession();

Full stack trace of any exception that occurs:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Hibernate: select vacation0_.vacationId as vacationId, vacation0_.startDate as startDate23_, vacation0_.endDate as endDate23_, vacation0_.year as year23_, vacation0_.type as type23_, vacation0_.kei as kei23_ from babadmin__vacation vacation0_
ERROR
could not execute query
select vacation0_.vacationId as vacationId, vacation0_.startDate as startDate23_, vacation0_.endDate as endDate23_, vacation0_.year as year23_, vacation0_.type as type23_, vacation0_.kei as kei23_ from babadmin__vacation vacation0_
java.sql.SQLException: Base table or view not found message from server: "Table 'babadmin.babadmin__vacation' doesn't exist"
org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:1502)
at org.hibernate.loader.Loader.list(Loader.java:1482)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:365)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:268)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:782)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at Test.main(Test.java:34)
Caused by: java.sql.SQLException: Base table or view not found message from server: "Table 'babadmin.babadmin__vacation' doesn't exist"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1997)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1167)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1278)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2251)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1586)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:107)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1183)
at org.hibernate.loader.Loader.doQuery(Loader.java:363)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:203)
at org.hibernate.loader.Loader.doList(Loader.java:1499)
... 6 more


Name and version of the database you are using:
MySQL 4.1

The generated SQL (show_sql=true):
select vacation0_.vacationId as vacationId, vacation0_.startDate as startDate23_, vacation0_.endDate as endDate23_, vacation0_.year as year23_, vacation0_.type as type23_, vacation0_.kei as kei23_ from babadmin__vacation vacation0_

Hi,

I am new to Hibernate and I am doing some tests.

I tried to execute the query directly in MySQL and the exception is the same, but if I change the from clause to "from vacation vacation0_" it works.

The problem is the same when I execute this code and when I double-click the Vacation class in the tree of the Hibernate Console (eclipse plugin).

Should I do take care about ISAM, MyISAM or innoDB (I am new to these considerations) ?

I have a subsidiary question concerning the plugin for eclipse. Should I use it to generate my class model ? I have already begin to design my class model in a UML graphical tool. I tried to use the reverse engeneering functionality and the generated classes are really close to my data model but not to my UML class model.

Thank you
Lilian


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 31, 2005 6:53 am 
Beginner
Beginner

Joined: Wed Mar 30, 2005 5:41 am
Posts: 40
I found the answer.

The mapping files generated by Hibernate Tools were containing a "catalog" attribute. I modified the template "persistentclass.hbm.vm" as follow and it works :

<$c2h.getTag($clazz)
#if(!$clazz.isDynamic())
name="$clazz.className"
#end
#if($clazz.isDynamic() || !$clazz.ClassName.equals($clazz.EntityName))
entity-name="$clazz.EntityName"
#end
#if($clazz.getSuperclass())
extends="$clazz.getSuperclass().className"
#end
table="$clazz.table.name"
#if ($clazz.table.schema)
schema="$clazz.table.schema"
#end
#if (! $clazz.mutable)
mutable="false"
#end
#if ($clazz.useDynamicUpdate())
dynamic-update="true"
#end
#if ($clazz.useDynamicInsert())
dynamic-insert="true"
#end
#if ($clazz.hasSelectBeforeUpdate())
select-before-update="true"
#end
#if (!$clazz.className.equals($clazz.discriminatorValue))
discriminator-value="$clazz.discriminatorValue"
#end
#if ($clazz.isExplicitPolymorphism())
polymorphism="explicit"
#end
#if ($clazz.isLazy() && !$clazz.className.equals($clazz.proxyInterfaceName))
proxy="$clazz.proxyInterfaceName"
#elseif (!$clazz.isLazy())
lazy="false"
#end
#if ($clazz.isAbstract())
abstract="true"
#end
#if ($c2h.isClassLevelOptimisticLockMode($clazz))
optimistic-lock="$c2h.getClassLevelOptimisticLockMode($clazz)"
#end
#if ($clazz.batchSize > 1)
batch-size="$clazz.batchSize"
#end
#if ($clazz.where)
where="$clazz.where"
#end
#if ($clazz.table.subselect)
subselect="$clazz.table.subselect"
#end
#if ($clazz.getClassPersisterClass())
persister="$clazz.getClassPersisterClass().name"
#end
#if ($clazz.table.rowId)
rowid="$clazz.table.rowId"
#end
>

Lilian


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 31, 2005 9:49 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
removing the catalog will introduce errors for those who are dependent on a catalog...but anyhow...this catalog bug is fixed in cvs and latest releasel

_________________
Max
Don't forget to rate


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.