-->
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: Please help with complicated UPDATE
PostPosted: Mon Sep 23, 2013 4:25 am 
Newbie

Joined: Sun Sep 22, 2013 11:00 pm
Posts: 1
Hi,
I have many years experience with SQL but I am new to Hibernate and Java. I have worked out the basics of Hibernate and built most of the required code.

The UPDATE logic below is what is required; however I changed the table names to make sure its not revealing company details.
Also please note the SQL must run as one SQL statement - other applications could update the tables at the same time this one is running.
The table design can't change as other applications are already in production using them.

Could someone please demonstrate how to do the update below in Hibernate?
Is createNativeQuery an option??

Thanks heaps for your help.

Code:
update
PERSON P
set
P.STATUS = 'Happy'
where
P.PK_ID = :person_id
and
(
select count(1)
from WORK_JOBS WJ
where WJ.RESOLVED_STATUS is null
) = 0
and
(
select count(1)
from EXPENSES EX
where EX.COST > :max_exp_cost
) = 0
;


The simplified table definitions are below.

Code:
create table PERSON
(
PK_ID         NUMBER NOT NULL,
LAST_NAME     VARCHAR2(100),
FIRST_NAME    VARCHAR2(100),
STATUS        VARCHAR2(30),
PRIMARY KEY   PK_ID
)
;
create table WORK_JOBS
(
PK_ID             NUMBER NOT NULL,
SUMMARY           VARCHAR2(100),
DESCRIPTION       VARCHAR2(1000),
RESOLVED_STATUS   VARCHAR2(50),
PRIMARY KEY       PK_ID
)
;
create table EXPENSES
(
PK_ID             NUMBER NOT NULL,
SUMMARY           VARCHAR2(100),
DESCRIPTION       VARCHAR2(1000),
COST              DECIMAL(10,2),
PRIMARY KEY       PK_ID
)
;


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.