-->
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.  [ 4 posts ] 
Author Message
 Post subject: calling oracle function using hibernate
PostPosted: Fri Dec 29, 2006 4:23 am 
Newbie

Joined: Fri Dec 29, 2006 3:14 am
Posts: 5
I have the need to call a function running a query having multiple joins from various tables and returning a oralce cursor.


The various files I have are:

hibernate.cfg.xml having the entry :
<!-- Mapping files -->
<mapping resource="test.hbm.xml"/>

test.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<sql-query name="prash_test" callable="true">
<return class="com.ni.genreg.presentation.formbeans.TestForm">
</return>
{ ? = call selectallemployments() }
</sql-query>
</hibernate-mapping>

TestForm
public class TestForm extends ValidatorForm {

private static GenRegLogger logger = GenRegLogger.getInstance(TestForm.class.getName());
private static final long serialVersionUID = 1L;
private String id;
private String firstname;
private String lastname;
private String email;
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}

}

Calling the oracle function
Session session = currentSession();
List li =session.getNamedQuery("prash_test").list();

Getting the following error in logs
[12/29/06 12:41:10:113 IST] 000000a9 EhCacheProvid W org.hibernate.cache.EhCacheProvider buildCache Could not find configuration [org.hibernate.cache.StandardQueryCache]; using defaults.
[12/29/06 12:41:10:206 IST] 000000a9 SessionFactor E org.hibernate.impl.SessionFactoryImpl <init> Error in named query: prash_test
org.hibernate.MappingException: Unknown entity: com.ni.genreg.presentation.formbeans.TestForm


any comments?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 29, 2006 8:00 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Well, it seems to only say that the class "com.ni.genreg.presentation.formbeans.TestForm" is not a mapped entity? Is it?

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject: calling oracle procedure using hibernate
PostPosted: Fri Dec 29, 2006 2:15 pm 
Newbie

Joined: Fri Dec 29, 2006 3:14 am
Posts: 5
Hi All,

I am new to hibernate.

Can somebody please tell me in simple steps how can I call a oracle procedure with a out parameter as a oracle type from java:

CREATE OR REPLACE TYPE user_type as object(
User_id Number(38),
title_name VARCHAR2(255),
FIRST_NAME VARCHAR2(255),
LAST_NAME VARCHAR2(255),
POSTAL_CODE VARCHAR2(255),
email VARCHAR2(255),
DOB Date);
/


Here's the procedure I want to call-

CREATE OR REPLACE procedure user_details(User_Type_Table OUT User_Type_Tab)
as
TYPE UserCurTyp IS REF CURSOR;
User_cv UserCurTyp;

v_User_id Number(38);
v_title_name VARCHAR2(255);
v_FIRST_NAME VARCHAR2(255);
v_LAST_NAME VARCHAR2(255);
v_POSTAL_CODE VARCHAR2(255);
v_email VARCHAR2(255);
v_DOB Date;
i Number;
v_max_sent_date Date;
v_max_Mod_date Date;
v_count Number;
BEGIN
OPEN User_cv FOR select
EUID.User_ID,
NTL.title_name,
EAPD.first_name,
EAPD.last_name,
EAPD.postal_code,
EUID.email,
EUID.dob
from NI_Title_Lookup NTL,
ERSMD_Address_Physical_Data EAPD,
ERSMD_User_Info_Data EUID
where NTL.title_id = EAPD.Title_id
and EAPD.ID = EUID.ID
and euid.user_id = 50
and (EUID.User_ID in (select user_id
from NI_USER_EMR_AUDIT NUEA
where EUID.User_id = NUEA.User_id
and status ='N'
and nvl(DELETED_IND,0) = 0
and sent_date =(select Max(sent_date)
from NI_USER_EMR_AUDIT NUEA1
where NUEA1.User_id = NUEA.User_id))
or EUID.User_ID not in (select user_id
from NI_USER_EMR_AUDIT NUEA
where EUID.User_id = NUEA.User_id));
i := 1;
User_Type_Table := User_Type_Tab();
Loop
Fetch User_cv into
v_User_id, v_title_name, v_FIRST_NAME, v_LAST_NAME, v_POSTAL_CODE, v_email, v_DOB;
exit when User_cv%notFound;

Select nvl(Max(sent_date), sysdate) into v_max_sent_date
from NI_USER_EMR_AUDIT NUEA
where NUEA.User_id = v_User_id;

Select Count(1) into v_count
from NI_USER_Bulletin_Info NUBI
where User_id = v_user_id;
If v_count > 0 Then
Select Greatest(Date_Created, Date_Modified, Date_Deleted) into v_max_Mod_date
from NI_USER_Bulletin_Info NUBI
where User_id = v_user_id;
else
v_max_Mod_date := v_max_sent_date+1;
end if;

If v_max_Mod_date > v_max_sent_date Then
User_Type_Table.extend;
User_Type_Table(i) := User_Type(v_User_id, v_title_name, v_FIRST_NAME, v_LAST_NAME, v_POSTAL_CODE, v_email, v_DOB);
i := i+1;
End if;
End loop;
Close user_cv;
End;
/


Please be as elaborate as possible.

Thanks in advance!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 29, 2006 3:46 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Is http://www.hibernate.org/hib_docs/v3/re ... l#sp_query enough elaborated? :-)

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


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