I have a class (ScoringEvent) that has a property defined by field access.
ScoringEvent.hbm.xml
Code:
<property name="grossScore" column="GROSS_SCORE"
access="field"
type="integer" />
ScoringEvent.java
Code:
public int grossScore = -999;
// only added for this testing to illustrate the behavior
public int getGrossScore() { return this.grossScore; }
TeamEvent and TeamMemberEvent extend ScoringEvent.
PairingEntry contains both a TeamEvent and TeamMemberEvent.
With my original mapping for PairingEntry:
Code:
<class name="PairingEntry"
table="pairing_entry" >
<id name="objectId" column="OID"
type="long" >
<generator class="identity"/>
</id>
<property name="order"
column="ENTRY_ORDER"
type="integer" />
<many-to-one name="pairing"
column="PAIRING_ID"
class="Pairing"
cascade="none" />
<many-to-one name="teamMemberEvent"
column="TEAM_MEMBER_EVENT_ID"
class="TeamMemberEvent"
cascade="none" />
<many-to-one name="teamEvent"
column="TEAM_EVENT_ID"
class="TeamEvent"
cascade="none" />
</class>
When applying the following tests, I get different results:
Code:
private static
void main( String[] args ) {
PairingEntry pairingEntry = null;
TeamEvent teamEvt = null;
System.out.println( "\n\nBY PAIRING" );
HIBMedalEventMgrImpl eventMgr = new HIBMedalEventMgrImpl();
Pairing pairing = eventMgr.getPairing( pairingId );
Iterator entryIter = pairing.getEntries().iterator();
while ( entryIter.hasNext() ) {
pairingEntry = (PairingEntry)entryIter.next();
printTeam( pairingEntry.getTeamEvent() );
}
HibernateUtil.closeSession();
System.out.println( "\n\nBY TEAM" );
teamEvt = (TeamEvent)HibernateUtil.currentSession().get( TeamEvent.class, new Long(14) );
printTeam( teamEvt );
HibernateUtil.closeSession();
System.out.println( "\n\nBY PAIRING ENTRY" );
pairingEntry = (PairingEntry)HibernateUtil.currentSession().get( PairingEntry.class, new Long(398) );
printTeam( pairingEntry.getTeamEvent() );
}
private static
void printTeam( TeamEvent teamEvt ) {
ScoringEvent se = teamEvt.getScoringEvent();
System.out.println( "TE: " + teamEvt.getObjectId() );
System.out.println( "TM: " + teamEvt.getTeamId() );
System.out.println( "SCORE 1: " + se.grossScore );
System.out.println( "SCORE 2: " + se.getGrossScore() );
System.out.println( "SCORE 3: " + se.grossScore );
}
BY PAIRING
TE: 14
TM: 21
SCORE 1: -999
SCORE 2: 14
SCORE 3: -999
TE: 16
TM: 30
SCORE 1: -999
SCORE 2: 0
SCORE 3: -999
BY TEAM
TE: 14
TM: 21
SCORE 1: 14
SCORE 2: 14
SCORE 3: 14
BY PAIRING ENTRY
TE: 14
TM: 21
SCORE 1: -999
SCORE 2: 14
SCORE 3: -999
As you can see there is a big difference in getting the TeamEvent directly (no proxy) and via the PairingEntry (proxy). Even with field access defined, the only way the value is properly retrieved is via getGrossScore().
HOWEVER....when I change the PairingEntry mapping for TeamEvent to be
Code:
<many-to-one name="teamEvent"
column="TEAM_EVENT_ID"
class="TeamEvent"
[color=red]lazy="false"[/color]
cascade="none" />
Everything works fine.
Couple of questions for anyone interested:
- is the correct behavior?
- where is this behavior defined (when using proxy all field level accessed properties are invalidated...re: need get/set)
Thanks in advance