-->
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: Problem using merge command
PostPosted: Wed Mar 19, 2008 2:16 pm 
Newbie

Joined: Tue Feb 12, 2008 9:52 am
Posts: 9
Hi,

I am using EJB3/JPA for our application .. We have a table that has got 2 million rows..every few seconds we have to insert new records into it.Since there is no assurance that the record will not duplicate from the UI part,
we have a composite key for that too.

The problem :
************

Previous developers used to check for the existence of that particular record in the DB using the composite key and if present,they will print a message in the log.Else they will persist the record using persist() method.

Since i thought it involves two hits to the DB, thought of using merge (keeping in mind that this would work similar to Hibernte's saveOrUpdate)..it abruptly failed..

Do we have anything in EJB3+JPA to just like that save the record whether it is new or old..won't the JPA detect as Hibernate does ?

If that feature is not there in EJB, isn't it limiting the powers of Hibernate, sitting on top of it ?

Any help would be appreciated.

--Venuwin


Top
 Profile  
 
 Post subject: Re: Problem using merge command
PostPosted: Wed Mar 19, 2008 2:30 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
Merge is not saveOrUpdate and the only way hibernate can do saveOrUpdate is by examining id column and comparing them to their unsaved value as specified. So you probably need to set a proper unsaved value for them and you are good.



Farzad-


Top
 Profile  
 
 Post subject: Clarification
PostPosted: Thu Mar 20, 2008 1:55 am 
Newbie

Joined: Tue Feb 12, 2008 9:52 am
Posts: 9
Hi Farzad,

Can u be specific about the approach that i need to do ?

Is there any approach available other than looking up the DB for the existence of the data and then firing a persist() if it doesn't exist in the DB.


Top
 Profile  
 
 Post subject: Re: Clarification
PostPosted: Thu Mar 20, 2008 4:13 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
Hmm, can you tell from the entity's primary key whether not it exists in db? If not, then you might want to look into putting a unique constraint on the keys and call insert each time. Upon a unique constraint exception then you might want to try to update it. However, I am not if this is the best way. We can wait to see if someone else has any better idea.


Farzad-


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.