-->
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: ManyToOne JoinTable ignores Lazy treated like SecondaryTable
PostPosted: Tue Dec 14, 2010 3:22 pm 
Newbie

Joined: Tue Dec 14, 2010 2:55 pm
Posts: 2
I have an entity that can have 0 or many children of the same entity. Also, the entity can have 0 or 1 parent of the same entity. This is a legacy table structure and I am unable to modify it.
Tables Structure
Code:
Account (
  AccountId PK,
  Name char
  etc...
)

AccountRef (
  ChildId PK, FK references Account(AccountId)
  ParentId PK, FK references Account(AccountId)
)


Everything is working correctly except any time I load an Account, a join is always done on the join table (I'm assuming to see if there is an AccountRef record), even though it is annotated Lazy. Also, it looks like hibernate is treating a ManyToOne on a JoinTable as a SecondaryTable?

Excerpt from log
Quote:
DEBUG org.hibernate.cfg.AnnotationBinder Processing annotations of Account.masterAccount
DEBUG org.hibernate.cfg.Ejb3Column Binding column: Ejb3JoinColumn{logicalColumnName='parentId', referencedColumn='accountId', mappedBy=''}
DEBUG org.hibernate.cfg.Ejb3Column Binding column: Ejb3Column{table=org.hibernate.mapping.Table(Account), mappingColumn=masterAccount, insertable=true, updatable=true, unique=false}
INFO org.hibernate.cfg.annotations.EntityBinder Adding secondary table to entity Account -> AccountRef
DEBUG org.hibernate.cfg.annotations.PropertyBinder Building property masterAccount
DEBUG org.hibernate.cfg.annotations.PropertyBinder Cascading masterAccount with none


Is the only way around this to use instrumentation for LazyToOne, or is there a better way to map this?
Code:
@Entity
Account {

@OneToMany(fetch=FetchType.LAZY, cascade=CascadeType.ALL, mappedBy="masterAccount")
     private Set<Account> subAccount;

@ManyToOne(fetch=FetchType.LAZY)
@JoinTable(name="AccountRef",
        joinColumns = @JoinColumn(name="childId", referencedColumnName="accountId"),
        inverseJoinColumns = @JoinColumn(name="parentId", referencedColumnName="accountId")
    )
     private Account masterAccount;


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.