0

Hibernate + ZK = weird results

asked 2008-04-27 16:58:48 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4931253

By: brendan4linux

Hi,
I'm pretty new to java programming, but I use netbeans and the nbxdoclet plugin to generate Objects and the data model. Everything is going great, but when I started creating and saving objects from zscript using hibernate (through generated Facade beans), I get inconsistent results. For example, I change a value of an object in my app, which will usually update on the next page refresh (on a page that lists these objects), but upon further requests/refreshes, it seems that the objects go back and forth from their new/original values, like something is being cached and not released.

I read about this on smalltalks, and tried to perform the necessary steps by adding org.zkoss.zkplus.hibernate.HibernateSessionContextListener
and org.zkoss.zkplus.hibernate.OpenSessionInViewListener, replacing asm.jar with the one from hibernate, but it looks like OpenSessionInViewListener wants to use hibernate.cfg.xml. I tried to put a sample hibernate.cfg.xml in WEB-INF/classes, but it fails to parse, although this hibernate.cfg.xml has worked before in other places.

The plugin uses hibernate.properties to setup it's hibernate configuration.
I'd like to keep everything as it is initially - i'm honestly not sure if I need to specify each mapping document for each object in hibernate.cfg.xml, or keep them in the same folder as the object itself (what i'm doing now).

Does what I described seem like a hibernate/zk threading issue, or something else? Do I have to use OpenSessionInViewListener and hibernate.cfg.xml, or can I continue using hibernate.properties?

Thanks in advance,
B

delete flag offensive retag edit

9 Replies

Sort by ยป oldest newest

answered 2008-04-28 02:29:19 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4931983

By: robbiecheng

What's the error message of parse failure of hibernate.cfg.xml?

/robbie

link publish delete flag offensive edit

answered 2008-04-28 04:23:45 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4932104

By: brendan4linux

See, that's what I'm having trouble seeing - I'm using the integrated Tomcat w/ netbeans 5.5, so it sends output to netbeans:
Caused by: org.hibernate.HibernateException: Could not parse configuration:
/hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1494)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1428)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1414)
at org.zkoss.zkplus.hibernate.HibernateUtil.java5Factory(HibernateUtil.j
ava:143)
at org.zkoss.zkplus.hibernate.HibernateUtil.initSessionFactory(Hibernate
Util.java:125)
... 29 more

For some reason I noticed that netbeans (maybe) seems to be putting a different hibernate3.jar file in with the build, one that I didn't provide, and seems to be different from the lib from the hibernate site. Thanks for the reply, i'm going to try to figure out what netbeans is doing.

link publish delete flag offensive edit

answered 2008-04-29 23:53:36 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4936297

By: brendan4linux

Don't know if anyone has seen this, but this seems to be the problem:

org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory

Has anyone seen / been able to resolve this?

Also, do I really need to specify
org.zkoss.zkplus.hibernate.OpenSessionInViewListener in zk.xml to use hibernate safely? Does the issue I described sound like a hibernate / zk threading issue?

Thanks again,
b

link publish delete flag offensive edit

answered 2008-04-30 00:33:56 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4936354

By: robbiecheng

Hi,

Please display a full stacktrace of this exception, or it's difficult to determine the issue.

By the way, is the problem of parsing hibernate.cfg.xml resolved?

/robbie

link publish delete flag offensive edit

answered 2008-04-30 00:55:11 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4936369

By: henrichen

org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory

This indicates that you have two DocumnetFactory class loaded from two different ClassLoaders for some reason. It is generally a configuration issue.

Did you put *.jar in Tomcat shared/lib and in WEB-INF/lib?

/henri

link publish delete flag offensive edit

answered 2008-04-30 18:15:06 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4937447

By: brendan4linux

Thanks Henri - that was exactly it - I figured out that netbeans was putting duplicate libs in my build.

I have all hibernate / zk libs in tomcat/common/lib. Should I put them in WEB-INF/lib as well? I think it sorted most of the issue out, but now I get:

org.hibernate.HibernateException: No CurrentSessionContext configured!
org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java
:542)
org.zkoss.zkplus.hibernate.HibernateUtil.currentSession(HibernateUtil.java:75)
org.zkoss.zkplus.hibernate.OpenSessionInViewListener.init(OpenSessionInViewList
ener.java:54)
org.zkoss.zk.ui.util.Configuration.invokeExecutionInits(Configuration.java:863)
org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage0(UiEngineImpl.java:300)
org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage(UiEngineImpl.java:265)
org.zkoss.zk.ui.http.DHtmlLayoutServlet.process(DHtmlLayoutServlet.java:227)
org.zkoss.zk.ui.http.DHtmlLayoutServlet.doGet(DHtmlLayoutServlet.java:167)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

Even though in my hibernate.cfg.xml, I have:
<property name="current_session_context_class">thread</property>

Thanks for all your help and patience.

b

link publish delete flag offensive edit

answered 2008-04-30 18:16:15 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4937449

By: brendan4linux

Please disregard the question above about putting jars in both common/lib and WEB-INF/lib - I should have all my class loading issues sorted out, I think.

link publish delete flag offensive edit

answered 2008-04-30 18:45:18 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4937504

By: brendan4linux

Ok, so I got my hibernate config issues worked out, I think, but even with the hibernate listeners and OpenSessionInViewListener I still get random values from my objects, although the new values have been persisted to the DB. Could this be another issue outside of hibernate?

Thanks,
B

link publish delete flag offensive edit

answered 2008-04-30 23:12:25 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4937962

By: brendan4linux

SOLVED! Chalk this one up to my own java ignorance - the Hibernate Facade Beans that netbeans generates use the full classpath to a custom HibernateUtil that it generated. So, I had to go back and modify all the generated Facade beans for my objects. Works like a champ now! Thanks for all the help.

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: 2008-04-27 16:58:48 +0800

Seen: 423 times

Last updated: Apr 30 '08

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