-->
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.  [ 7 posts ] 
Author Message
 Post subject: Event Listener Configuration, hibernate.cfg.xml
PostPosted: Tue Mar 17, 2009 9:36 pm 
Beginner
Beginner

Joined: Thu Feb 21, 2008 3:31 pm
Posts: 34
Hi all,

I have a very simple Event Listener that simply applies the date to an object being updated or saved. The problem I am having is my hibernate.cfg.xml is coming up invalid?

I am using maven to build my project (hibernate annotations 3.4, core 3.3, seach and validator 3.1).

I added these entries to my configuration:

Code:
<?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 name="java:/hibernateSession">
.
.
.
<event type="pre-insert">
         <listener class="com.walterjwhite.persistence.hibernate.event.CurrentDateListener"/>
      </event>
      <event type="pre-update">
         <listener class="com.walterjwhite.persistence.hibernate.event.CurrentDateListener"/>
      </event>


Code:
Caused by: org.xml.sax.SAXParseException: The content of element type "session-factory" must match "(property*,mapping*,(class-cache|collection-cache)*,event*,listener*)".
   at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
   at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)
   at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:387)
   at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:321)
   at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleEndElement(XMLDTDValidator.java:2020)
   at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.endElement(XMLDTDValidator.java:904)
   at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1750)
   at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2906)
   at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:624)
   at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:116)
   at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:486)
   at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:810)
   at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:740)
   at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:110)
   at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1208)
   at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:525)
   at org.dom4j.io.SAXReader.read(SAXReader.java:465)
   at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1518)
   ... 61 more



The error I am having is, when hibernate is parsing this document, it throws a parsing exception? I do not have a persistence.xml and my dependencies (hibernate) seems to match up according to their compatibility matrix.

First of all, am I using the event and listener tags appropriately?

Thanks,
Walter


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 17, 2009 10:35 pm 
Newbie

Joined: Sun Jan 28, 2007 10:37 pm
Posts: 4
Location: Wollongong
try moving session-factory below event in the file.


Top
 Profile  
 
 Post subject: configuration
PostPosted: Wed Mar 18, 2009 8:22 pm 
Beginner
Beginner

Joined: Thu Feb 21, 2008 3:31 pm
Posts: 34
Hi,

Thanks for your reply.

Just to be clear ... session-factory is an element within hibernate-configuration and both event and listener are nested inside session-factory. Event and LIstener cannot be outside session-factory as it would not apply to anything.

The best I found elsewhere (both in hibernate.org, and elsewhere) was pretty much the setup I am using.

I can't explain why I am getting this error unless I have a dependency in my classpath that I shouldn't, but that doesn't appear to be the problem.

Any other ideas?


Thanks,
Walter


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 18, 2009 11:12 pm 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
base on this : (property*,mapping*,(class-cache|collection-cache)*,event*,listener*)", have you put your event below property, mapping, class-cache?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 18, 2009 11:24 pm 
Beginner
Beginner

Joined: Thu Feb 21, 2008 3:31 pm
Posts: 34
Hi,

Thanks for your reply! That was indeed the problem. I have some other minor issues to work out with the listeners, but that got me over the hurdle.


I misunderstood the response previously. Why is it that ordering matters in the XML?

Walter


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 20, 2009 12:02 pm 
Newbie

Joined: Fri Mar 20, 2009 11:55 am
Posts: 2
I has found the problem,
this property: <property name="hibernate.cache.provider_class">
must before the property :<mapping resource="xx.hbm.xml"/>,
I use the JBPM appear the same error:The content of element type "session-factory" must match "(property*,mapping*,(class-cache|collection-cache)*,event*,


Top
 Profile  
 
 Post subject: Re: Event Listener Configuration, hibernate.cfg.xml
PostPosted: Mon Nov 15, 2010 3:42 pm 
Newbie

Joined: Mon Nov 15, 2010 3:38 pm
Posts: 1
Is it possible to disable a particular eventlistener programatically for a particular session? If so, pls paste the sample code.

Thanks,
Sridhar


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