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.  [ 3 posts ] 
Author Message
 Post subject: findByExample and composite primary key ignored
PostPosted: Wed Jun 21, 2006 1:40 pm 
Using 3.1.3.

I have an old DB with some composite keys (yay! fun mappings!) and my first POJO has a composite-id in a class of its own with the keys as below.

After running tests and inspecting the SQL output, it seems doing a findByExample ignores the values in the composite-id. Is there a method to tell Hibernate to incorporate the composite-id key values in the findByExample search?

As you can see, I'm using an interface for the entity POJO.

//composite primary key class
public class CardHolderId implements java.io.Serializable
{
private String paNumber;
private Short sequenceNumber;
etc......

//entity itself
public class BasicCardHolder implements java.io.Serializable, CardHolder
{
private CardHolderId id;
private String title;
private String firstName;
private String lastName;


Mapping:
Code:
  <class name="BasicCardHolder"
    entity-name="CardHolder" table="CRDDET"
    lazy="false">
    <composite-id name="id"
      class="CardHolderId">
      <key-property name="paNumber" type="string">
        <column name="PAN" length="19" />
      </key-property>
      <key-property name="sequenceNumber" type="short">
        <column name="SEQNO" />
      </key-property>
    </composite-id>
    <etc etc......


Top
  
 
 Post subject:
PostPosted: Thu Jun 22, 2006 1:13 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
No. From the ref docs, section 15.6, "Example queries":
Version properties, identifiers and associations are ignored. By default, null valued properties are excluded.

You could map the relvant columns twice: perhaps like this:
Code:
  <class name="BasicCardHolder"
    entity-name="CardHolder" table="CRDDET"
    lazy="false">
    <composite-id name="id"
      class="CardHolderId">
      <key-property name="paNumber" type="string">
        <column name="PAN" length="19" />
      </key-property>
      <key-property name="sequenceNumber" type="short">
        <column name="SEQNO" />
      </key-property>
    </composite-id>

    <property name="paNumberValue" formula="PAN"/>
    <property name="sequenceNumberValue" formula="SEQNO"/>
    <etc etc......
The two new properties are read only (because they use formula="" instead of column=""), but can still be used to query by example.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 22, 2006 4:53 am 
Ok, thanks, I overlooked that statement in the docs, probably because I was concentrating on getting a one-to-many association to work with Example Query.

Your double mapping solution looks good initially but I think with the extra setters and getters on the persistent object, it will add more complexity than the current slightly verbose Criteria setup I have in the DAO.

In fact in this situation I think what I am going to do is just ditch Example Query and pass in the parameters seperately.


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