-->
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: Stored Procedures
PostPosted: Thu Feb 24, 2005 7:27 pm 
Newbie

Joined: Mon Jun 07, 2004 12:59 pm
Posts: 13
Can anyone point me toward some code that demonstrates a call to a stored procedure using the updatePerson function and Person mapping files on p. 131 of the reference manual for Hibernate 3?

TIA
Allan M. Hart


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 24, 2005 9:28 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
The source has some test cases that are worth reviewing


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 25, 2005 7:18 pm 
Newbie

Joined: Mon Jun 07, 2004 12:59 pm
Posts: 13
David..

Thanks for the tip.

My current problem is that Hibernate complains about the following mapping file taken from p. 131.

<?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="org"
default-access="field">

<class name="Person">
<id name="id">
<generator class="increment"/>
</id>
<property name="name" not-null="true"/>
<sql-insert callable="true">{call createPerson (?, ?)}</sql-insert>
<sql-delete callable="true">{? = call deletePerson (?)}</sql-delete>
<sql-update callable="true">{? = call updatePerson (?, ?)}</sql-update>
</class>
</hibernate-mapping>

<!--
<sql-insert callable="true">{call createPerson (?, ?)}</sql-insert>
<sql-delete callable="true">{? = call deletePerson (?)}</sql-delete>
<sql-update callable="true">{? = call updatePerson (?, ?)}</sql-update>

<sql-insert>INSERT INTO PERSON (NAME, ID) VALUES (UPPER(?), ? )</sql-insert>
<sql-update>UPDATE PERSON SET NAME=UPPER(?) WHERE ID=?</sql-update>
<sql-delete>DELETE FROM PERSON WHERE ID=?</sql-delete>

-->

The specific complaint is:

[java] Caused by: org.xml.sax.SAXParseException: The content of element type "class" must match
"(meta*,subselect?,cache?,synchronize*,(id|composite-id),discriminator?,(version|timestamp)?,(prope
rty|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|p
rimitive-array|query-list)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?
,sql-update?,sql-delete?,filter*)".

The odd thing is that this is taken straight from p. 131 of the reference manual. The other odd thing is that if I use

<sql-insert>INSERT INTO PERSON (NAME, ID) VALUES (UPPER(?), ? )</sql-insert>
<sql-update>UPDATE PERSON SET NAME=UPPER(?) WHERE ID=?</sql-update>
<sql-delete>DELETE FROM PERSON WHERE ID=?</sql-delete>

i.e., don't use the "callable="true"" version, I get no complaints from Hibernate.

Any help would be most appreciated.

TIA
Allan M. Hart


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 25, 2005 11:02 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
The XML parser should accept this since the DTD has the callable attribute. Maybe check your version of HIbernate 3 and the DTD.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 28, 2005 6:02 pm 
Newbie

Joined: Mon Jun 07, 2004 12:59 pm
Posts: 13
Hi David..

O.k., I've checked the Hibernate version and the DTD and can find nothing wrong. Here's my log file:

15:37:21,455 INFO Environment:456 - Hibernate 3.0rc1
15:37:21,465 INFO Environment:469 - hibernate.properties not found
15:37:21,465 INFO Environment:502 - using CGLIB reflection optimizer
15:37:21,465 INFO Environment:532 - using JDK 1.4 java.sql.Timestamp handling
15:37:21,465 INFO Configuration:1228 - configuring from resource: /hibernate.cfg.xml
15:37:21,475 INFO Configuration:1199 - Configuration resource: /hibernate.cfg.xml
15:37:21,776 DEBUG DTDEntityResolver:42 - trying to locate http://hibernate.sourceforge.net/hibern ... on-3.0.dtd in classpath under org/hibernate/
15:37:21,776 DEBUG DTDEntityResolver:53 - found http://hibernate.sourceforge.net/hibern ... on-3.0.dtd in classpath
15:37:21,836 DEBUG Configuration:1185 - connection.driver_class=oracle.jdbc.driver.OracleDriver
15:37:21,836 DEBUG Configuration:1185 - connection.url=jdbc:oracle:thin:@134.29.51.11:1521:hart
15:37:21,836 DEBUG Configuration:1185 - dialect=org.hibernate.dialect.OracleDialect
15:37:21,836 DEBUG Configuration:1185 - connection.username=hart
15:37:21,836 DEBUG Configuration:1185 - connection.password=hart
15:37:21,836 DEBUG Configuration:1185 - show_sql=true
15:37:21,836 DEBUG Configuration:1185 - hbm2ddl.auto=create
15:37:21,846 DEBUG Configuration:1380 - null<-org.dom4j.tree.DefaultAttribute@1968e23 [Attribute: name resource value "org/Person.hbm.xml"]
15:37:21,846 INFO Configuration:439 - Mapping resource: org/Person.hbm.xml
15:37:21,846 DEBUG DTDEntityResolver:42 - trying to locate http://hibernate.sourceforge.net/hibern ... ng-3.0.dtd in classpath under org/hibernate/
15:37:21,846 DEBUG DTDEntityResolver:53 - found http://hibernate.sourceforge.net/hibern ... ng-3.0.dtd in classpath
15:37:21,946 ERROR XMLHelper:59 - Error parsing XML: XML InputStream(19) The content of element type "class" must match "(meta*,subselect?,cache?,synchronize*,(id|composite-id),discriminator?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array|query-list)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*)".

Here's my Person.hbm.xml file:

<?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="org"
default-access="field">

<class name="Person">
<id name="id">
<generator class="increment"/>
</id>
<property name="name" not-null="true"/>
<sql-insert callable="true">{call createPerson (?, ?)}</sql-insert>
<sql-delete callable="true">{? = call deletePerson (?)}</sql-delete>
<sql-update callable="true">{? = call updatePerson (?, ?)}</sql-update>
</class>
</hibernate-mapping>

Here's my Person.java file:

package org;

public class Person {

private Long id;
private String name;

public Person() {}

public Person(String name) {
this.name = name;
}

public Long getId() {
return id;
}

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

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}

Here's my driver (Test.java):

package org;

import java.math.BigDecimal;
import org.hibernate.*;
import org.hibernate.cfg.Configuration;
import org.hibernate.Criteria;

import java.util.*;
import java.util.List;
public class Test {

private static SessionFactory sessionFactory;

public static void main(String[] args) throws Exception {
final Test app = new Test();

// Build SessionFactory
try {
app.sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (HibernateException e) {
throw e;
}

// Hibernate placeholders
Session session = null;
Transaction tx = null;
java.io.Serializable courseId = null;

try {
session = app.sessionFactory.openSession();
tx = session.beginTransaction();
Person person = new Person();
person.setName("Allan");
session.save(person);
tx.commit();
} catch (HibernateException e) {
System.out.println(e.getMessage());
tx.rollback();
e.printStackTrace();
} finally {
if (session != null)
session.close();
}

// Close the SessionFactory (not mandatory)
app.sessionFactory.close();
}
}

Any help would be most appreciated.

TIA,
Allan M. Hart


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 28, 2005 6:52 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
your xml is somehow breaking the dtd. i cant see whats wrong so maybe you have to play around to fix it ,)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 01, 2005 2:12 pm 
Newbie

Joined: Mon Jun 07, 2004 12:59 pm
Posts: 13
O.k. guys, I've made some "progress". The following Person.hbm.xml file parses without incident:

<?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="org"
default-access="field">
<class name="Person">
<id name="id">
<generator class="increment"/>
</id>
<property name="name" not-null="true"/>
<sql-insert callable="true">{call createPerson (?, ?)}</sql-insert>
<sql-delete callable="true">{? = call deletePerson (?)}</sql-delete>
</class>
</hibernate-mapping>

However, this one causes the complaint:

<?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="org"
default-access="field">
<class name="Person">
<id name="id">
<generator class="increment"/>
</id>
<property name="name" not-null="true"/>
<sql-insert callable="true">{call createPerson (?, ?)}</sql-insert>
<sql-delete callable="true">{? = call deletePerson (?)}</sql-delete>
<sql-update callable="true">{? = call updatePerson(?, ?)}</sql-update>
</class>
</hibernate-mapping>

So it would appear that the problems lies in the line

<sql-update callable="true">{? = call updatePerson(?, ?)}</sql-update>

Any ideas?

TIA,
Allan M. Hart


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 01, 2005 3:59 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
if that files parses without problems, what is the remaing problem ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 01, 2005 4:31 pm 
Newbie

Joined: Mon Jun 07, 2004 12:59 pm
Posts: 13
?? I guess I'm confused by your response. The remaining problem is simply that the file with the <sql-update >.... </sql-update> stuff in it won't parse. This, even though, the file is exactly the same as the one in the Hibernate3 reference manual.

Allan M. Hart


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 01, 2005 5:48 pm 
Newbie

Joined: Mon Jun 07, 2004 12:59 pm
Posts: 13
I thought I had posted this before but I must have forgotten to hit the submit button.


O.k., I seem to have located the "problem". The following file parses without error:

<?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="org"
default-access="field">
<class name="Person">
<id name="id">
<generator class="increment"/>
</id>
<property name="name" not-null="true"/>
<sql-insert callable="true">{call createPerson (?, ?)}</sql-insert>
<sql-update callable="true">{? = call updatePerson(?, ?)}</sql-update>
<sql-delete callable="true">{? = call deletePerson (?)}</sql-delete>
</class>
</hibernate-mapping>

Note that this is the same as the file that produces a parsing error except for the order of the <sql...>...</sql...> lines.

This still seems odd to me but at least I can go forward now.

Thanks for all your help and if anyone knows why the ordering of those lines should make a difference, I'd love to know.


Regards,
Allan M. Hart


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 01, 2005 8:16 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
because thats what the DTD specifices ,)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 03, 2005 1:12 pm 
Newbie

Joined: Mon Jun 07, 2004 12:59 pm
Posts: 13
Hi Max..

O.k., after checking the dtd, I can see that you're right.

My only remaining question is whether the Hibernate3 reference manual should be updated? The code that I originally worked with and that broke the dtd comes straight out of that manual.

TIA
Allan M. Hart


Top
 Profile  
 
 Post subject: Additional comment on the order of elements in the DTD.
PostPosted: Mon Mar 07, 2005 5:09 pm 
Newbie

Joined: Thu Mar 03, 2005 3:25 pm
Posts: 5
I believe there is a bug in the DTD here because the order of the elements is
inconsistent. In nearly every case, the sequence is:
sql-insert?,sql-update?,sql-delete?,sql-delete-all?...

In the subclass declaration, the order differs:
sql-insert?,sql-delete?,sql-update?

I can't think of a good reason to change the order in one place -- and it can sure be confusing.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 08, 2005 6:29 pm 
Newbie

Joined: Mon Jun 07, 2004 12:59 pm
Posts: 13
Hi davidmarkcarlson...

I'm not sure what you mean by the "subclass" declaration. My problem was with the last mapping file at the bottom of p. 131 of the reference manual. The order there seems wrong.

On a related note. I was unable to get the example code on pp. 131-132 to work until I changed not only the order of the <sql-....>---</sql-...> tags in the mapping file but also the order of the parameters in the stored procedure. In other words, I had to change the code that appears at the very bottom of p. 131 to this:

CREATE OR REPLACE FUNCTION updatePerson(uname IN VARCHAR2, UID IN NUMBER)
RETURN NUMBER IS
BEGIN

....

END updatePerson;

You're right. It's confusing.

Allan M. Hart


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 09, 2005 4:48 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Two issues here:

One is that we had a bug in the DTD that wanted a certain sequence of sql-xxx in <class> and another in <subclass> - that should be fixed in the CVS now.

The other about changing the order of parameters in the stored procedure I cant reproduce since it works here. Are you using the
exact same hbm.xml as listed in the documentation ?

Remember that if you change the order of properties et.al. in the mapping you are also changing how the stored procedure is called.
(We are working on making this easier to use by having named parameters instead of ?)

/max

_________________
Max
Don't forget to rate


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.