-->
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.  [ 15 posts ] 
Author Message
 Post subject: Help with Stored Procedures
PostPosted: Thu Apr 20, 2006 12:57 pm 
Newbie

Joined: Thu Apr 20, 2006 12:30 pm
Posts: 7
Hi

I'm evaluating Hibernate and have a very simple Hibernate app consisting of a bean with 3 fields, a Sybase table with 3 fields, a utility class which creates a session factory and a main class which decides whether to list or insert data depending on the parameters passed to it.

I then try and modify .hbm.xml file to allow a stored procedure to be used - I've basically cut and pasted the code from 16.3.2 of the documentation and modified it to use my class and property names. I've haven't modified anything else, but now my app won't run. I keep getting loads of XML errors for my .hbx.xml file complaining of missiong atttributes which are NOT missing. Please see below for details.


Hibernate version: 3.1

Mapping documents:

<?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>

<class name="de.gloegl.road2hibernate.Event" table="COCKPIT_EVENTS_TEST">
<id name="id" column="uid" type="long">
<generator class="increment"/>
</id>
<property name="dt_datem" type="timestamp"/>
<property name="title" column="eventtitle"/>

</class>

<!-- When this code sql-query is removed, it all works well -->
<sql-query callable="true" name="Hibernate_Test">
<return alias="ce" class="de.gloegl.road2hibernate.Event">
<return-property name="id" column="uid"/>
<return-property name="dt_datem" column="dt_datem"/>
<return-property name="title" column="eventtitle"/>
</return>
{ ? = call Hibernate_Test() }
</sql-query>

</hibernate-mapping>

[Full stack trace of any exception that occurs:

INFO - Hibernate 3.0rc1
INFO - hibernate.properties not found
INFO - using CGLIB reflection optimizer
INFO - using JDK 1.4 java.sql.Timestamp handling
INFO - configuring from resource: /hibernate.cfg.xml
INFO - Configuration resource: /hibernate.cfg.xml
INFO - Mapping resource: de/gloegl/road2hibernate/Event.hbm.xml
ERROR - Error parsing XML: XML InputStream(17) Attribute "callable" must be decl
ared for element type "sql-query".
ERROR - Error parsing XML: XML InputStream(19) Element type "return-property" mu
st be declared.
ERROR - Error parsing XML: XML InputStream(20) Element type "return-property" mu
st be declared.
ERROR - Error parsing XML: XML InputStream(21) Element type "return-property" mu
st be declared.
ERROR - Error parsing XML: XML InputStream(22) The content of element type "retu
rn" must match "EMPTY".
Initial SessionFactory creation failed.org.hibernate.MappingException: Error rea
ding resource: de/gloegl/road2hibernate/Event.hbm.xml
Exception in thread "main" java.lang.ExceptionInInitializerError
at de.gloegl.road2hibernate.HibernateUtil.<clinit>(HibernateUtil.java:24
)
at de.gloegl.road2hibernate.EventManager.listEvents(EventManager.java:39
)
at de.gloegl.road2hibernate.EventManager.main(EventManager.java:22)
Caused by: org.hibernate.MappingException: Error reading resource: de/gloegl/roa
d2hibernate/Event.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:447)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.jav
a:1381)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.jav
a:1353)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1335)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1302)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1230)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1216)
at de.gloegl.road2hibernate.HibernateUtil.<clinit>(HibernateUtil.java:20
)
... 2 more
Caused by: org.hibernate.MappingException: invalid mapping
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:394
)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:444)
... 9 more
Caused by: org.xml.sax.SAXParseException: Attribute "callable" must be declared
for element type "sql-query".
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAX
ParseException(Unknown Source)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unk
nown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(
Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(
Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.addDTDDef
aultAttrsAndValidate(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleSta
rtElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElem
ent(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scan
StartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImp
l$FragmentContentDispatcher.dispatch(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImp
l.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(U
nknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(U
nknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown So
urce)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Un
known Source)
at org.dom4j.io.SAXReader.read(SAXReader.java:334)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:393
)
... 10 more


Once I remove the <sql-query> fragment, the app works, but I need to get it working with Stored Procs. I've cut and pasted the <sql-query> fragment from the docs, so not sure where I'm going wrong. And I've tried placing the sql-query within the class tag and I get the same error.

Any help appreciated!

Cheers

Patrick.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 20, 2006 1:42 pm 
Senior
Senior

Joined: Wed Aug 17, 2005 12:56 pm
Posts: 136
Location: Erie, PA (USA)
Do you have any <query> ... </query> tags in your mapping that you didn't show? I've seen a problem with parsing the mapping file if <sql-query>...</sql-query> tags preceed the <query>...</query tags.

Curtis ...

_________________
---- Don't forget to rate! ----


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 20, 2006 2:53 pm 
Regular
Regular

Joined: Wed Feb 22, 2006 11:28 am
Posts: 65
Location: Santiago, Chile
Hello Friend:

I was verifing your problem poists, i found a tag which probly generate your problem:
if you see your sql-query code, you put {} in your sql-query.

I think, for a elegancy and good practice, you can write:

<![CDATA[
{ ? = call Hibernate_Test() }
]]>

after return tag.

Request for comments.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 21, 2006 7:08 am 
Newbie

Joined: Thu Apr 20, 2006 12:30 pm
Posts: 7
Thanks for your responses.

Curtis: There's nothing else in the mapping file

neketsushonen: I've tried the CDATA thing, but I get the same error. I've even tried removing the { ? = call Hibernate_Test() } line completely and I get the same error.

Has anyone got Hibernate to work with Stored Procs? I searched a lot on google and through this forum, but can find no definitive example of this, just snippets of code.

Cheers

Patrick.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 21, 2006 7:19 am 
Newbie

Joined: Fri Apr 21, 2006 5:44 am
Posts: 3
Location: UK
patricko,

I am finding the same lack of info on this topic, frustratingly! I am going to post a general query about using stored procedures - without Oracle


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 21, 2006 9:05 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
looks to me that you are using an *old* dtd.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 21, 2006 9:30 am 
Newbie

Joined: Thu Apr 20, 2006 12:30 pm
Posts: 7
Thanks for your reply Max. Could you tell me what DTD I should be using?

There is no 3.1 DTD, at least not under the same URL structure.

Cheers

Patrick.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 21, 2006 9:41 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
just use the latest release hibernate3.jar.

the error says <return-property> is not defined, but it is.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 21, 2006 11:05 am 
Newbie

Joined: Thu Apr 20, 2006 12:30 pm
Posts: 7
Hi

I was using the latest 3.1.3 prod jar. I've updated to the 3.2 CR (which isn't ideal as it isn't prod) and I can get the SP to work (!!!), although it took quite a bit of fiddling and even now I get CGLIB enhancement failures (???) regardless of whether I have the SP stuff in my .hbm.xml.

But I can get the SP to run!

Cheers

Patrick.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 21, 2006 11:16 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
should work equally fine in 3.1.x though.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 21, 2006 11:21 am 
Newbie

Joined: Thu Apr 20, 2006 12:30 pm
Posts: 7
i can tell you that it doesn't work in 3.1.3.

patrick.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 21, 2006 11:32 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
and i can tell you that the junit tests for this works fine in hibernate 3.1.3 :)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 21, 2006 12:09 pm 
Newbie

Joined: Thu Apr 20, 2006 12:30 pm
Posts: 7
then why have i had this problem, the solution being to update a later version of hibernate?

when i had the <sql-query> stuff in my .hbm.xml mapping file, it didn't work against the hibernate jar shipped with 3.1.3 prod, the errors being in the previous email. when i remove the <sql-query> tags, my hibernate app works ok. when i run my app with the <sql-query> tags against the jar shipped with 3.2 CR, it works ok.

cheers

patrick.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 21, 2006 12:29 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
can't say - take a look at the examples in docs and in our unit test and see if you can spot a difference.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 08, 2007 9:48 pm 
Newbie

Joined: Sun Apr 08, 2007 9:44 pm
Posts: 1
I faced the same problem.

I put all the <sql-query> after the <class> definitions and it doesn't show the error message anymore.

<?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 package="XXX">

<class name="YYY" ...>
...
</class>

<!-- sql-query must be after class -->

<sql-query name="getNextSequenceNumber">
<return-scalar column="seq" type="long" />
<![CDATA[
SELECT ZZZ_SEQ.NEXTVAL FROM DUAL
]]>
</sql-query>

</hibernate-mapping>


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