Results 1 to 2 of 2
  1. #1
    ibjava is offline Member
    Join Date
    May 2008
    Posts
    3
    Rep Power
    0

    Lightbulb How to get object from composite-id in Hibernate?

    Hi all, im new here, and newbie in java also

    I usually get an object using id, which that id as the only PK, just like this:
    Deposito deposito = dao.getDeposito(depositoId);

    but now my Deposito doesn't allow to have id field, and have multiple PKs, here's the hbm code snipplet:
    <composite-id>
    <key-many-to-one name="dimTime" column="TIME_KEY"/>
    <key-many-to-one name="dimLocation" column="LOCATION_KEY"/>
    <key-property name="accountNumber" column="ACCOUNT_NUMBER" length="7"/>
    </composite-id>

    my question is:
    How to get object that have composite-id in Hibernate?

    actually i want to ask this question in this thread, I got it from google search, but im affraid it's gonna be OOT.

    so, please help me & thanx b4!!:cool:

  2. #2
    ibjava is offline Member
    Join Date
    May 2008
    Posts
    3
    Rep Power
    0

    Default

    sorry, i forget to show the code for getting Deposito in one id, here's my code:

    public Deposito getDeposito(Long id) {
    Deposito deposito = (Deposito) getHibernateTemplate().get(Deposito.class, id);
    if (deposito == null) {
    throw new ObjectRetrievalFailureException(Deposito.class, id);
    }
    return deposito;
    }

    Im not change it yet, but now I got trouble to get it with many PK.

Similar Threads

  1. composite-id problem hibernate
    By javadev in forum JDBC
    Replies: 14
    Last Post: 07-27-2009, 07:30 PM
  2. composite key Hibernate
    By Problem in forum Web Frameworks
    Replies: 0
    Last Post: 07-25-2007, 12:13 PM
  3. Replies: 2
    Last Post: 06-30-2007, 04:01 PM
  4. composite-id and hibernate
    By Marty in forum JDBC
    Replies: 1
    Last Post: 05-28-2007, 05:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •