-->
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.  [ 2 posts ] 
Author Message
 Post subject: Criteria object can't access attribute?
PostPosted: Tue Jun 23, 2009 3:55 pm 
Newbie

Joined: Mon Jun 22, 2009 12:11 pm
Posts: 5
Hello,

I am new to Hibernate and am having problems accessing an attribute in my class with a Criteria object. This particular attribute is a class, and I need to query on one of that class's attributes. I can get one of the attributes, and I'm wondering if there is a "better" way to get attributes that are part of a class that is an attribute to my main class. Here is my Criteria object:

...
String pran = searchCriteria.getPran();
if (pran != null && !pran.equals("")) {
LOGGER.debug("Adding PRAN");
conditionalCriteria.add(Expression.eq("account.pran", pran));
}
String authNum = searchCriteria.getAuthNum();
if (authNum != null && !authNum.equals("")) {
LOGGER.debug("Adding AUTH");
conditionalCriteria.add(Expression.eq("authNum", authNum));
}
...

where "pran" is actually an attribute of the Account class, and the Account class is an attribute of the main object I'm searching on. The mapping:

...
<id name="oid" type="integer" column="TRAN_ID"/>
<many-to-one name="account" class="com.prenet.domain.client.customer.Account" column="ACCT_NUM"
not-null="true"/>
<property name="tranAmount" type="double" column="TRAN_AMOUNT"/>
<property name="transmissionDateTime" type="date" column="TRANSMISSION_DATE_TIME"/>
<property name="span" type="string" column="CARRIER_ACCT_NUM"/>
<property name="cin" type="string" column="GEN_NUM_1"/>
...

So that setup works for the pran attribute only. i.e. "account.pran" does indeed map the correct SQL, but attempting to access any other attribute of the Account class in similar fashion blows up with errors that look like this:

org.hibernate.QueryException: could not resolve property: account.proxyCin

My main class has an attribute which is the Account class:
...
private Account account;

public Account getAccount() {
return account;
}

public void setAccount(Account account) {
this.account = account;
}
...

Where the Account class is (keep in mind the account.pran works perfectly):

...
private String pran;
private String proxyCin;

public String getPran() {
return pran;
}

public void setPran(String pran) {
this.pran = pran;
}

public String getProxyCin() {
return proxyCin;
}

public void setProxyCin(String proxyCin) {
this.proxyCin = proxyCin;
}


Is there a better way to get attributes of inner classes like this?

Thanks in advance,
Pedro


Top
 Profile  
 
 Post subject: Re: Criteria object can't access attribute?
PostPosted: Wed Jul 01, 2009 1:45 pm 
Newbie

Joined: Mon Jun 22, 2009 12:11 pm
Posts: 5
So the answer to this is...it can't be done. Hibernate currently will not know anything about the properties in embedded objects, only the IDs...so account.pran works because "pran" is mapped as the ID, but account.proxy does not because "proxy" is mapped as a property. The only way to get around this seems to be to add a sqlrestriction, like this guy did:

viewtopic.php?f=1&t=997933&p=2414277#p2414277

...it works, but looks hacky and i haven't found a way to make those bind variables yet. Hope this helps someone.

Pedro


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