-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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
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>
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
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
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.
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>
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
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
Asked: 2009-12-17 02:33:06 +0800
Seen: 757 times
Last updated: Jan 12 '10