• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception while calling stored proc from hibernate. URGENT Help

 
Jitu Ji
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a stored proc as given following:

procedure get_all_users_report( PO_RESULT OUT gt_cursor
)
as
v_insert varchar(4000);
begin
INSERT INTO tmp_usersreport(userinfo_id , username, isactive)
(
SELECT userinfo_id , username, isactive
FROM userinfo
WHERE isactive = 1
);
open PO_RESULT for
select username from tmp_usersreport;

end get_all_users_report;tmp_usersreport

tmp_usersreport is a global temp table defined in ORACLE DB.

My Hibernate mapping is called sp.hbm.xml:

<?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="UserReport" table="tmp_usersreport">
<property name="username" column="username"/>
</class>
<sql-query name="test_SP" callable="true">
<return alias="UserReport" class="UserReport">
</return>
{? = call test_pkg.get_all_users_report(?) }
</sql-query>
</hibernate-mapping>

<?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>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">jdbcracle:thin:@localhost:1521:XE</property>
<property name="hibernate.connection.username">System</property>
<property name="hibernate.connection.password">test</property>
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="show_sql">false</property>
<mapping resource="sp.hbm.xml"/>

</session-factory>
</hibernate-configuration>


My return DTO is:


public class UserReport implements java.io.Serializable{

String username;

public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}



Java Code to call stored proc:

List<UserReport> users;
try
{
Session sessionObj = HibernateUtil.currentSession();
Transaction tx = sessionObj.beginTransaction();
users = sessionObj.getNamedQuery("test_SP").list();
System.out.println(users.size());

Iterator it = users.iterator();
while(it.hasNext())
{
UserReport menu = (UserReport) it.next();
}

HibernateUtil.closeSession();

Exception is:

Initial SessionFactory creation failed.org.hibernate.MappingException: Could not read mappings from resource: sp.hbm.xml
Exception in thread "main" java.lang.ExceptionInInitializerError
at HibernateUtil.<clinit>(HibernateUtil.java:17)
at test4.test(test4.java:55)
at test4.main(test4.java:17)
Caused by: org.hibernate.MappingException: Could not read mappings from resource: sp.hbm.xml

Please Help. This is my first post here.

Thanks in adv.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags when posting code or configuration. Unformatted code and configuration is very difficult to read. You can edit your post to include them by using the button.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is your mapping file located?
 
Jitu Ji
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my mapping file is in the same folder where my Java files are.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you need to add the package directories here

<mapping resource="sp.hbm.xml"/>

Because with that above, it will try to find the xml file in the root of the classpath, where it does not exist.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic