-->
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: @Embeddable object an Criteria Search do not seem to combin
PostPosted: Tue Dec 19, 2006 11:04 am 
Newbie

Joined: Fri May 12, 2006 9:48 am
Posts: 14
Location: Toulouse
Hibernate version:
3.2.1 GA

Hi all,


I want to use Criteria for implementing Finder functions.
I did some finders make work, so my environment (with Spring) seems to work just fine.
Now, I want to use a Criteria search with an object that is Embedded.
This is my base object:

Code:
@Entity
public class DataStrip implements Serializable {
   

   private Integer dataStripId; //PK

   private DataStripIdentification dataStripIdentification;
   
   ..................


   @Id
   @GeneratedValue(strategy=GenerationType.IDENTITY)
   @Column(name="datastrip_id")
   public Integer getDataStripId() {
      return dataStripId;
   }

   public void setDataStripId(Integer dataStripId) {
      this.dataStripId = dataStripId;
   }
   

   public DataStripIdentification getDataStripIdentification() {
      return dataStripIdentification;
   }

   public void setDataStripIdentification(
         DataStripIdentification dataStripIdentification) {
      this.dataStripIdentification = dataStripIdentification;
   }

   ..........

   @Transient
   public String getDataStripReference() {
      return getDataStripIdentification().getDataStripReference();
   }
}


This is my Embeddable object:

Code:
@Embeddable
public class DataStripIdentification implements Serializable {

   private Integer dataStripId; //PK
   private DataStrip dataStrip;

   private String dataStripReference; //unique

   ...............

   @Id
   @Column(name="datastrip_id")
   public Integer getDataStripId() {
      return dataStripId;
   }

   public void setDataStripId(Integer dataStripId) {
      this.dataStripId = dataStripId;
   }

   @OneToOne(fetch=FetchType.LAZY)
   @PrimaryKeyJoinColumn
   public DataStrip getDataStrip() {
      return dataStrip;
   }

   public void setDataStrip(DataStrip dataStrip) {
      this.dataStrip = dataStrip;
   }

   @Column(name="id_datastrip_reference",unique=true)
   public String getDataStripReference() {
      return dataStripReference;
   }

   public void setDataStripReference(String dataStripReference) {
      this.dataStripReference = dataStripReference;
   }

   ..............
}



Now I want to write a finder that returns me a DataStrip with the dataStripReference as parameter.

I did try several combinations.

Code:
public DataStrip getDataStrip(String dataStripReference) {
//  TEST 1:
//      DetachedCriteria criteria = DetachedCriteria.forClass(DataStrip.class);
//      DetachedCriteria dsIDcriteria = criteria.createCriteria("dataStripIdentification");
//      dsIDcriteria.add(eq("dataStripReference", dataStripReference));
//      criteria.setFetchMode("dataStripIdentification",FetchMode.JOIN);
//      List mylist = hibernate.findByCriteria(criteria);
//      logger.debug("================"+mylist.size());
//      DataStrip ds = (DataStrip)getUniqueResult(mylist);
//      logger.debug("ds:"+ds.getDataStripId()+"||"+ds.getDataStripReference());
//      return ds;

// TEST 2:      
//      DetachedCriteria criteria = DetachedCriteria.forClass(DataStrip.class)
//      .setFetchMode("dataStripIdentification",FetchMode.JOIN)
//      .add(eq("dataStripReference", dataStripReference));
//      List mylist = hibernate.findByCriteria(criteria);
//      logger.debug("================"+mylist.size());
//      DataStrip ds = (DataStrip)getUniqueResult(mylist);
//      logger.debug("ds:"+ds.getDataStripId()+"||"+ds.getDataStripReference());
//      return ds;
      
// TEST 3:      
      DataStrip ds = getDataStrip(1);
      logger.debug("----------------"+ds.getDataStripReference());
      logger.debug("----------------"+dataStripReference);
      DetachedCriteria dsIDcriteria = DetachedCriteria.forClass(DataStripIdentification.class)      
      .add(eq("dataStripReference", dataStripReference));
      List mylist = hibernate.findByCriteria(dsIDcriteria);
      logger.debug("================"+mylist.size());
      DataStripIdentification id = (DataStripIdentification)getUniqueResult(mylist);
      logger.debug("id:"+id.getDataStripId()+""+id.getDataStripReference());
      return getDataStrip(id.getDataStripId());
   }



If I run the part of TEST1 or TEST2, I get next exception:

Code:
org.springframework.orm.hibernate3.HibernateQueryException: could not resolve property: dataStripReference of: phr.ipu.cat.data.metadata.datastrip.DataStrip; nested exception is org.hibernate.QueryException: could not resolve property: dataStripReference of: phr.ipu.cat.data.metadata.datastrip.DataStrip
org.hibernate.QueryException: could not resolve property: dataStripReference of: phr.ipu.cat.data.metadata.datastrip.DataStrip
   at org.hibernate.persister.entity.AbstractPropertyMapping.throwPropertyException(AbstractPropertyMapping.java:43)


There is no sql output to be found in the log file !

If I run the part of TEST3 (I first do a getDataStrip by ID to verify the content of the first datastrip is the same of the one I am looking for by DataStripReference):

Code:
INFO  [19/12/06 11:22:30] (SettingsFactory.java:296) - Default entity-mode: pojo
INFO  [19/12/06 11:22:30] (SessionFactoryImpl.java:161) - building session factory
INFO  [19/12/06 11:22:32] (SessionFactoryObjectFactory.java:82) - Not binding factory to JNDI, no JNDI name configured
DEBUG [19/12/06 11:22:32] (AbstractBatcher.java:393) - select datastrip0_.datastrip_id as datastrip1_2_5_, datastrip0_.id_datastrip_reference as id12_2_5_, ....... from DataStrip datastrip0_ where datastrip0_.datastrip_id=?
DEBUG [19/12/06 11:22:32] (DataStripFacadeImpl.java:70) - ----------------DS_PHR1A_07140000001100_xxx_PA_E000N00_0011_00714
DEBUG [19/12/06 11:22:32] (DataStripFacadeImpl.java:71) - ----------------DS_PHR1A_07140000001100_xxx_PA_E000N00_0011_00714
DEBUG [19/12/06 11:22:32] (DataStripFacadeImpl.java:76) - ================0


The exception is a NullPointerException because I amdoing a id.getDataStripId() of something that is null (because nothing found in the finder).

The thing that also amazes me is there is no query shown in the log where Hibernate is calling the db by 'SELECT ....FROM DataStrip WHERE id_datastripreference = ?'

Is there anyone who sees what I do wrong (if so) ? Or what I can do to make it work (otherwise) ? Or are we talking about a bug ?

TIA, Jan


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.