-->
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.  [ 1 post ] 
Author Message
 Post subject: Need help in executing in sql server procedure in hibernate
PostPosted: Thu Apr 03, 2008 8:11 am 
Newbie

Joined: Thu Apr 03, 2008 7:56 am
Posts: 2
hi,

iam newbie to hibernate and sql server 2005.
i want to know how do we execute sql server 2005 stored procedure
in hibernate.

Below is my database tables:

Database tables:

CREATE TABLE CL_USER_DETAILS(
USER_ID INT IDENTITY (1,1) PRIMARY KEY,
USER_NAME NVARCHAR(20) UNIQUE NOT NULL,
USER_SSN NVARCHAR(100) UNIQUE NOT NULL,
USER_SALUTATION NVARCHAR(5) NOT NULL,
USER_FIRST_NAME NVARCHAR(50) NOT NULL,
USER_LAST_NAME NVARCHAR(50) NOT NULL,
USER_PASSWORD NVARCHAR(50) NOT NULL,
USER_CREATED_TIMESTAMP DATETIME,
USER_MODIFIED_TIMESTAMP DATETIME,
USER_CREATED_BY INT,
USER_MODIFIED_BY INT,
USER_FIRM_ID INT,
USER_SUPERVISOR INT,
USER_STATUS NVARCHAR(20) NOT NULL REFERENCES CL_USER_STATUS(USER_STATUS),
FIRM_USER_INDEX INT
)

CREATE TABLE CL_FIRM_DETAILS(
FIRM_ID INT IDENTITY (1,1) PRIMARY KEY,
FIRM_CUSTOMER_CODE NVARCHAR(20) UNIQUE NOT NULL,
FIRM_REGISTERED_NAME NVARCHAR(100) UNIQUE NOT NULL,
FIRM_USER_COUNT INT NOT NULL,
FIRM_CONTRACT_START_DATE DATETIME NOT NULL,
FIRM_CONTRACT_END_DATE DATETIME NOT NULL,
FIRM_CREATED_TIMESTAMP DATETIME NOT NULL,
FIRM_MODIFIED_TIMESTAMP DATETIME NOT NULL,
FIRM_STATUS NVARCHAR(20) NOT NULL REFERENCES CL_FIRM_STATUS(FIRM_STATUS),
CREATED_BY INT REFERENCES CL_USER_DETAILS(USER_ID),
MODIFIED_BY INT REFERENCES CL_USER_DETAILS(USER_ID),
FIRM_DESCRIPTION NVARCHAR(200) NOT NULL
)

CREATE TABLE CL_CONTACT_DETAILS(
CONTACT_ID INT IDENTITY (1,1) PRIMARY KEY,
ADDRESS1 NVARCHAR(100) NOT NULL,
ADDRESS2 NVARCHAR(100) NOT NULL,
COUNTRY_CODE NVARCHAR(100) NOT NULL,
STATE_CODE NVARCHAR(100) NOT NULL,
CITY_CODE FLOAT NOT NULL,
PHONE_NUM NVARCHAR(100) NOT NULL,
MOBILE_NUM NVARCHAR(100) ,
MAIL_ID NVARCHAR(100) NOT NULL,
FAX NVARCHAR(30) NULL,
ZIPCODE NVARCHAR(30) NOT NULL,
FIRM_ID INT REFERENCES CL_FIRM_DETAILS(FIRM_ID),
USER_ID INT REFERENCES CL_USER_DETAILS(USER_ID),
FIRM_CONTACT_INDEX INT,
USER_CONTACT_INDEX INT
)



Here is my SQL server 2005 procedure:


use [master]
go
use [db]
go

CREATE PROC GetFirmsByPage

@PageSize int, @PageNumber int

AS

Declare @RowStart int
Declare @RowEnd int

if @PageNumber > 0
Begin

SET @PageNumber = @PageNumber -1

SET @RowStart = @PageSize * @PageNumber + 1;
SET @RowEnd = @RowStart + @PageSize - 1 ;

With firms AS
(
SELECT
firm.FIRM_ID,
firm.FIRM_CUSTOMER_CODE,
firm.FIRM_REGISTERED_NAME,
firm.FIRM_USER_COUNT,
firm.FIRM_STATUS,
firm.FIRM_DESCRIPTION,
contact.CONTACT_ID as contactId,
contact.MAIL_ID as mailId
ROW_NUMBER() OVER (order by firm.FIRM_ID) as RowNumber

FROM
CL_FIRM_DETAILS firm,CL_CONTACT_DETAILS contact

WHERE
firm.FIRM_ID=contact.FIRM_ID AND
firm.FIRM_STATUS!= 'Deleted'

)

select *
from firms
WHERE RowNumber BETWEEN @RowStart AND @RowEnd

END


How do it execute the above stored procedure in hibernate.

How show it write <sql-query> for multiple tables and classess.
and access the same from my dao using
getHibernateTemplate().findByNamedQuery();


i wrote:

<sql-query name="firm_listing" callable="true">
<return alias="firm" class="com.centrilaw.lpo.firm.dto.FirmDTO">
<return-property name="firmId" column="FIRM_ID" />
<return-property name="firmCustomerCode" column="FIRM_CUSTOMER_CODE" />
<return-property name="firmRegisteredName" column="FIRM_REGISTERED_NAME" />
<return-property name="totalUserCount" column="FIRM_USER_COUNT" />
<return-property name="firmStatus" column="FIRM_STATUS" />
<return-property name="description" column="FIRM_DESCRIPTION" />
</return>

exec GetFirmsByPage 10, 2
</sql-query>

its giving erroring saying invalid column name.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.