-->
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: find failed with component mapping
PostPosted: Thu Nov 20, 2008 8:26 am 
Newbie

Joined: Thu Nov 20, 2008 8:14 am
Posts: 6
I am using "component" to map some of the columns to an aggregated class. The mapping is done with annotation and works fine with loadAll. However the find failed with the following error. Can anyone give me any direction for the troubleshooting? Thanks.

2008-11-20 20:20:50,109 - c.e.c.d.ContractDao [main] [ERROR]: find by property name failed
org.springframework.orm.hibernate3.HibernateQueryException: could not resolve property: contracttag of: com.eclipseoptions.eodata.persistence.instrument.Instrument [from com.eclipseoptions.eodata.persistence.instrument.Instrument as model where model.contracttag= ?]; nested exception is org.hibernate.QueryException: could not resolve property: contracttag of: com.eclipseoptions.eodata.persistence.instrument.Instrument [from com.eclipseoptions.eodata.persistence.instrument.Instrument as model where model.contracttag= ?]


The code fragment to build the query string and retrieve the record:

String queryString = "from Instrument as model where model." + "contracttag" + "= ?";
return getHibernateTemplate().find(queryString, value);



The class structure is like this.

package com.eclipseoptions.eodata.persistence.instrument;
@Entity
@Table(name = "contracts")
public class Instrument
{
.
private InstrumentId instrumentId;
.
}
@Embeddable
public class InstrumentId{

.
@Column
private int contracttag;
.
}
The table schema:
CREATE TABLE contracts
(
id integer NOT NULL ,
username char(64),
contracttag integer NOT NULL ,
.
.
)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 20, 2008 2:30 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Code:
....where model.contracttag....


You'll need to "go into" the component using dot notation. Try:

Code:
....where model.instrumentId.contracttag....


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 20, 2008 9:11 pm 
Newbie

Joined: Thu Nov 20, 2008 8:14 am
Posts: 6
Hi nordborg,
Yes it works finally. I tried using model.InstrumentId which is the class name but failed. Thanks a lot for your help


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2008 12:10 am 
Newbie

Joined: Thu Nov 20, 2008 8:14 am
Posts: 6
Can i define the @Id of the whole structure in an embedded object?

ie.

package com.eclipseoptions.eodata.persistence.instrument;
@Entity
@Table(name = "contracts")
public class Instrument
{
.
private InstrumentId instrumentId;
.
}

@Embeddable
public class InstrumentId{

.
@Id
private int contracttag;
.
}

CREATE TABLE contracts
(
id integer NOT NULL ,
username char(64),
contracttag integer NOT NULL ,
.
.
)


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.