-->
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: Query by Example and primary key
PostPosted: Wed Jan 14, 2004 3:40 am 
Newbie

Joined: Wed Jan 14, 2004 3:21 am
Posts: 2
Hey!

I am trying to write a query by example, but i faced the following problem.
If am passing an example object, with a primary key field initialized, then i get back the list of all records in my table.

of course one of the possibilities is to write own implementation of PropertySelector. but i would like to write fetch methods that can be used with any persistent object.

Here is my example
Code:
  public Object getObjectByExample(Object object) throws HibernateException {
    List objectList = this.getObjectListByExample(object);

    object = (objectList.isEmpty() ? null : objectList.get(0));

    return object;
  }


  public List getObjectListByExample(Object object) throws HibernateException {
    Session session = DaoSession.open();

    Example example = Example.create(object);

    List objectList = session.createCriteria(object.getClass()).add(example)
                             .list();

    return objectList;
  }

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2004 4:45 am 
Newbie

Joined: Wed Jan 14, 2004 3:21 am
Posts: 2
i have found in the documentation the following line
Quote:
Version propeties, identifiers and associations are ignored

Why it is so?
And what is a defualt implementation of PropertySelector interface used when i create new Example instance by passing only example object?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2004 6:07 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
version is a technical tool, requesting by version has no business meaning.
If you know the identity, then you know the object, just do load(class, pk).
Example query is done to do a "looks like" query, not an exact query.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: PropertySelector with composed-key
PostPosted: Mon Aug 22, 2005 3:47 am 
Newbie

Joined: Mon Aug 22, 2005 3:42 am
Posts: 1
Hello,

I am facing the same problem with key properties included in the key.


I have this kind of mapping

<class name="com.real.aof.to.db.BWFF" table="AOFSQL_6.AOFBWFF" lazy="false">

<composite-id>
<key-property name="jobNumber" column="BFJBNR" />
<key-property name="archiveNumber" column="BFINNR" />
<key-property name="documentNumber" column="BFDONR" />
<key-property name="sequenceNumber" column="BFSEQ" />
</composite-id>

<property name="fromFolderID" column="BFFIIF" />
<property name="documentName" column="BFDONM" />
<property name="toFolderID" column="BFFIIT" />
<property name="yesFolderID" column="BFFIIY" />
<property name="noFolderID" column="BFFIIN" />
<property name="approbationRequired" column="BFAPRQ" />
<property name="triggeredProgram" column="BFPGM" />
<property name="text" column="BFTEXT" />

</class>

I would like to make QBE with only a part of the composed-key (5 fields for instance) and it is easier to use QBE than declare a cunch of queries for each combination of properties.


Do you have a suggestion ? Which class to extend to enable this ?
Thanks a lot


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.