0

ZK + Hibernate

asked 2009-12-17 02:33:06 +0800

ahmad gravatar image ahmad
138 1

Hi All, I have followed tutorial chapter in zk developer guide which talked about how to use hibernate with zk, and perform all steps in it.
The resulting sample works good on my local machine, but after uploading database table and war file to a remote host, it does not work, it gives me a strange exception, following snaps of source code and exception.

1 - hibernate.cfg.xml file:

...........
	<session-factory>
    	<!-- Database Connection settings -->
		<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
		<property name="connection.url">jdbc:mysql://localhost:3307/adelzayed?autoReconnect=true</property>
		<property name="connection.username">adelzayed</property>
		<property name="connection.password">{myPassword}</property>
		
		<!-- JDBC connection pool (use the built-in) -->
		<property name="connection.pool_size">1</property>
		
		<!-- SQL dialect -->
		<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
		
		<!-- Enable Hibernate's automatic session context management -->
		<property name="current_session_context_class">thread</property>
		
		<!-- Disable the second-level cache -->
		<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
		
		<!-- Echo all executed SQL to stdout -->
		<property name="show_sql">true</property>
		
		<mapping resource="events/Event.hbm.xml"/>
	</session-factory>
..................

of course, I have changed database url, user name, and password to match those of remote host.

2 - Event.hbm.xml file

...........................
<hibernate-mapping>
<class name="events.Event" table="EVENTS">
	<id name="id" column="EVENT_ID">
		<generator class="native"/>
	</id>
	<property name="date" type="timestamp" column="EVENT_DATE"/>
	<property name="title"/>
</class>
</hibernate-mapping>
...........................

3 - Event.java file

.......................
import java.util.Date;

public class Event {
	private Long id;
	private String title;
	private Date date;

	public Event() {

	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}
}

4 - EventDAO.java file

...................
import java.util.Date;
import java.util.List;

import org.hibernate.Session;
import org.zkoss.zkplus.hibernate.HibernateUtil;

public class EventDAO {

	Session currentSession() {
		return HibernateUtil.currentSession();
	}

	public void saveOrUpdate(Event anEvent, String title, Date date) {
		Session session = currentSession();
		anEvent.setTitle(title);
		anEvent.setDate(date);
		session.saveOrUpdate(anEvent);
	}

	public void delete(Event anEvent) {
		Session session = currentSession();
		session.delete(anEvent);
	}

	public Event findById(Long id) {
		Session session = currentSession();
		return (Event) session.load(Event.class, id);
	}

	public List findAll() {
		Session session = currentSession();
		return session.createQuery("from Event").list();
	}
}

5 - Exception stack trace:

org.hibernate.exception.SQLGrammarException: could not execute query
	org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
	org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
	org.hibernate.loader.Loader.doList(Loader.java:2223)
	org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
	org.hibernate.loader.Loader.list(Loader.java:2099)
	org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
	org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
	org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
	org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
	org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
       	events.EventDAO.findAll(EventDAO.java:34)
	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...................................
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'adelzayed.EVENTS' doesn't exist
	sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
	sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
	java.lang.reflect.Constructor.newInstance(Constructor.java:513)
	com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
	com.mysql.jdbc.Util.getInstance(Util.java:381)
	com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
	com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
	com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3515)
	com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3447)
	com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1951)
	com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101)
	com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2554)
	com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1761)
	com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1912)
	org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
	org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
	org.hibernate.loader.Loader.doQuery(Loader.java:674)
	org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
	org.hibernate.loader.Loader.doList(Loader.java:2220)
	org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
	org.hibernate.loader.Loader.list(Loader.java:2099)
	org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
	org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
	org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
	org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
	org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
	events.EventDAO.findAll(EventDAO.java:34)
	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
....................

What your suggestions about error?
Thank you for Concern.
Ahmad Elsafty

delete flag offensive retag edit

8 Replies

Sort by » oldest newest

answered 2009-12-17 04:00:53 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2009-12-17 04:02:19 +0800

is this surely your database name and the rights for that are set?

<property name="connection.url">jdbc:mysql://localhost:3307/adelzayed?autoReconnect=true</property>

link publish delete flag offensive edit

answered 2009-12-17 05:24:25 +0800

jentrees gravatar image jentrees
51 1

Table 'adelzayed.EVENTS' doesn't exist

This is a exception throwed by hibernate but not any relation between zk and hibernate.

link publish delete flag offensive edit

answered 2009-12-17 06:43:11 +0800

ahmad gravatar image ahmad
138 1

Hi all, Thanks all for reply.

is this surely your database name and the rights for that are set?

<property name="connection.url">jdbc:mysql://localhost:3307/adelzayed?autoReconnect=true</property>
yes"terrytornado", I am sure of that, I took this url from technical support team of my host site.

Table 'adelzayed.EVENTS' doesn't exist

This is a exception throwed by hibernate but not any relation between zk and hibernate.

I think so "jentrees", but there is an issue, the table named "events" (lower case) in database and named "EVENTS" in mapping file, but I do not think that is the problem.
What are your opinions?
Thanks all again.
Ahmad Elsafty

link publish delete flag offensive edit

answered 2009-12-17 06:46:32 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2009-12-17 06:49:44 +0800

Hmmm, i mean if the table doesn't exists than the first error you must see is a hibernate Mapping error.

So i think it's a right problem on the database

link publish delete flag offensive edit

answered 2009-12-17 07:01:49 +0800

caclark gravatar image caclark
1753 2 5
http://clarktrips.intltwi...
    I think so "jentrees", but there is an issue, the table named "events" (lower case) in database and named "EVENTS" in mapping file, but I do not think that is the problem.
If you successfully developed and tested on Windows and are having trouble deploying onto Linux or another case sensitive operating system, this is exactly the problem. I deal with it all the time while developing on XP and deploying on CentOS. The one piece of code you didn't show is the DDL used to create the table in MySQL. I have my DDL with case sensitive names and my mapping file match. Since it doesn't matter on Windows, anything will work. This solution then works on case sensitive operating systems. Notice the grave accent characters surrounding the table name in the CREATE statement so that MySQL takes it literally.
CREATE TABLE IF NOT EXISTS `Facilities` (
    ...
) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;
    <class name="com.mst.soms.model.Facility" table="Facilities">
        ...
    </class>    
link publish delete flag offensive edit

answered 2009-12-17 12:40:22 +0800

ahmad gravatar image ahmad
138 1

Hi all, Thank you "terrytornado".
"caclark", you are right, it is a matter of case sensitivity, I have used a single naming convension for database in mapping, configuration, and db schema, and my problem is solved.
الحمد لله
Thanks to God
Many Thanks to all.
Ahmad Elsafty

link publish delete flag offensive edit

answered 2010-01-12 01:35:13 +0800

machosotft gravatar image machosotft
3

Hello, good people!!!

same one can tell me how can I resolve this exception or error:
org.zkoss.zk.ui.impl.UiEngineImpl handleError:1131
SEVERE: >>java.lang.NoClassDefFoundError: org/hibernate/criterion/Criterion


Macho from Mozambique

link publish delete flag offensive edit

answered 2010-01-12 01:48:22 +0800

PeterKuo gravatar image PeterKuo
481 2

According to the error message,
org/hibernate/criterion/Criterion
It seems like you didn't have some jars of hibernate in your class path.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-12-17 02:33:06 +0800

Seen: 757 times

Last updated: Jan 12 '10

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More