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.  [ 5 posts ] 
Author Message
 Post subject: how to access property of Base class
PostPosted: Fri Sep 22, 2006 8:28 pm 
Newbie

Joined: Mon Aug 01, 2005 8:12 pm
Posts: 19
Location: CA
Version: Hibernate version3.

Mapping document as follows:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="com.redbull.prism.distsearch.domainmodel">
<class
name="Distributor"
table="Distributor"
>
<meta attribute="sync-DAO">false</meta>

<meta attribute="sync-DAO">false</meta>

<meta attribute="sync-DAO">false</meta>

<id
name="Id"
type="integer"
column="distbr_sap_no"
>
<generator class="native"/>
</id>

<property
name="DistbrNm"
column="distbr_nm"
type="string"
not-null="true"
length="50"
/>
<property
name="FedTaxNo"
column="fed_tax_no"
type="string"
not-null="false"
length="10"
/>
<property
name="WebSite"
column="web_site"
type="string"
not-null="false"
length="50"
/>
<property
name="StartDt"
column="start_dt"
type="timestamp"
not-null="true"
length="23"
/>
<property
name="EndDt"
column="end_dt"
type="timestamp"
not-null="true"
length="23"
/>
<property
name="CreateDt"
column="create_dt"
type="timestamp"
not-null="true"
length="23"
/>
<property
name="UpdateDt"
column="update_dt"
type="timestamp"
not-null="true"
length="23"
/>
<many-to-one
name="SalesOffice"
column="sales_office_id"
class="SalesOffice"
not-null="false"
>
</many-to-one>
<many-to-one
name="DistbrType"
column="distbr_type_id"
class="DistributorType"
not-null="true"
>
</many-to-one>
<many-to-one
name="FtpFreq"
column="ftp_freq_id"
class="DistributorFtpFrequency"
not-null="false"
>
</many-to-one>
<many-to-one
name="Nielson"
column="nielson_id"
class="Nielson"
not-null="false"
>
</many-to-one>
<many-to-one
name="UserNo"
column="user_no"
class="Users"
not-null="true"
>
</many-to-one>
<many-to-one
name="OwnerDistbrNo"
column="owner_distbr_no"
class="DistributorConglomerate"
not-null="false"
>
</many-to-one>

<set
inverse="true"
lazy="true"
name="DistributorLocations"
>
<key column="distbr_sap_no" />
<one-to-many class="DistributorLocation" />
</set>

<set
inverse="true"
lazy="true"
name="DistributorTerritories"
>
<key column="distbr_sap_no" />
<one-to-many class="DistributorTerritory" />
</set>



</class>
</hibernate-mapping>.


code is as follows:
Session hbSession = HibernateUtil.getSessionFactory().getCurrentSession();
hbSession.beginTransaction();
Query query = hbSession.createQuery(GET_DISTRIBUTOR_LIST);
query.setString("distributorName",distributorName);
List distributorList = query.list();
hbSession.getTransaction().commit();


Full stack trace of any exception that occurs:
could not resolve property: distBrNm of: com.redbull.prism.distsearch.domainmodel.Distributor [from com.redbull.prism.distsearch.domainmodel.Distributor as dist where dist.distBrNm=:distributorName]


DB Version:SQL Server 2000


The HQL: from Distributor as dist where dist.distBrNm=:distributorName


The above exception is coming because my Distributor class extends BaseDistributor class generated by hibernate synchronizer. Now distBrNm is a private property of BaseDistributor class. So how to access that private propery of base class in Distributor class in the above mentioned scenario.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 23, 2006 11:49 am 
Beginner
Beginner

Joined: Fri Jul 08, 2005 8:09 am
Posts: 28
I am not sure if I understand this correctly. Do you have a scenario like this:


Code:
class BaseDistributor
{
  private long distBrNo;
  public long getDistBrNo() { return distBrNo; }
  public void setDistBrNo(long distBrNo) { this.distBrNo = distBrNo; }
}

class Distributor extends BaseDistributor
{}


If so you just have to make sure that the Hibernate mapping maps the Distributor class, not the BaseDistributor class. According to the quoted mapping this is already the case. Are getters and setters in the base class private or how is your situation here? In this case you will have to make them public I guess, or increase visibility in the descendant class.

DC


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 24, 2006 1:52 pm 
Newbie

Joined: Mon Aug 01, 2005 8:12 pm
Posts: 19
Location: CA
Yes, your understanding is correct. But I don't want to make my variables public. So what is your suggestion.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 25, 2006 5:10 am 
Beginner
Beginner

Joined: Fri Jul 08, 2005 8:09 am
Posts: 28
Since Hibernate subclasses the persistent classes it can access protected fields and methods, I suppose. So try to make everything protected...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 25, 2006 12:42 pm 
Newbie

Joined: Mon Aug 01, 2005 8:12 pm
Posts: 19
Location: CA
Can I make it through Hibernate Synchronizer?


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