-->
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.  [ 2 posts ] 
Author Message
 Post subject: Getting IDs of existing detached instances, creating others
PostPosted: Fri May 28, 2010 7:42 pm 
Newbie

Joined: Mon Nov 23, 2009 1:17 pm
Posts: 5
I always feel guilty for posting in these kinds of forums because I know my question has been answered before, I just don't know what to search to find it.

I have URLs stored in a table (essentially just an ID and the text of the URL link) and they need to be globally unique. For performance, I have a data structure that stores some instances in memory to minimize trips to the database. When I parse a web page and it has several links, I want to efficiently find all the URLs that already exist in the database, and create those that don't. Specifically:

  • Check my in-memory cache of URL instances, comparing the text of the URL. Return the matching detached instances.
  • Check the database for existing URL instances, detach those instances, cache them in the in-memory cache for future use, and return them. The slow way of doing this is, for each URL,
    Code:
    URL u = (URL) s.createCriteria(URL.class).add(Restrictions.eq("url_text", "www.example.com")).uniqueResult();
    if (u != null) {
        ...
    }
  • For the remaining URLs, create new URL instances and save them in the database. Cache them in the in-memory cache for future use.

How can do this efficiently/in bulk? I'm basically coming to Hibernate with fully initialized URL POJO's except for the persistent ID, and I just need Hibernate to "fill in" the ID with existing IDs or allocate new ones. What I would like to do is similar to an "upsert", but different because I don't want to update existing instances, and that query doesn't return back any of the rows. thanks in advance for any help!


Top
 Profile  
 
 Post subject: Re: Getting IDs of existing detached instances, creating others
PostPosted: Thu Jun 03, 2010 2:54 am 
Newbie

Joined: Mon Nov 23, 2009 1:17 pm
Posts: 5
Does a anyone have any ideas or can anyone point me to where in the documentation it talks about this kind of topic? thanks


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