-->
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: Subcriteria for Example via Embedded object
PostPosted: Mon Oct 15, 2007 10:26 am 
Newbie

Joined: Mon Oct 15, 2007 10:01 am
Posts: 3
Hibernate version: 3.2.5

Hi, colleagues!

I have a hard time creating the correct Criteria with Examples for the following setup:

Code:
@Entity
class Branch {

    @Id
    BranchPK getId()
}

-----------------------

@Embeddable
class BranchPK {

    @Column(name="BRANCH_NUM")
    Long getBranchNumber()

    @ManyToOne
    Bank getBank()
}

----------------

@Entity
class Bank{

    @Id
     Long getId()
}


Now I have an example object:

Code:
Bank bank = new Bank();
bank.setId(12);

BranchPK id = new BranchPK();
id.setBank(bank);
id.setBranchNumber(345);

Branch branch = new Branch();
branch.setId(id);


Since Hibernate doesn't include the associations in example object by default, but requires subcriteria for it, I have to pass via the embedded object to add the bank subcritera.

I have tried 4 options:

1. Ignoring the embeddness of the id fields:
Code:
Criteria criteria = session.createCriteria(Branch.class).add(Example.create(branch)).createCriteria("bank").add(Example.create(bank));


2. Add the id to the bank subcriteria path:
Code:
Criteria criteria = session.createCriteria(Branch.class).add(Example.create(branch)).createCriteria("id.bank").add(Example.create(bank));


3. Add the id as separate subcriteria:
Code:
Criteria criteria = session.createCriteria(Branch.class).add(Example.create(branch)).createCriteria("id").createCriteria("bank").add(Example.create(bank));


4. Add the id object as another example (as it was assocciation):
Code:
Criteria criteria = session.createCriteria(Branch.class).add(Example.create(branch)).createCriteria("id").add(Example.create(id)).createCriteria("bank").add(Example.create(bank));


Non of the options works.

Could you please point me on what I am doing wrong?

Thanks in advance,

Baruch.


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.