-->
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: private field overriden
PostPosted: Mon Oct 27, 2008 11:09 am 
Newbie

Joined: Sun May 14, 2006 7:31 am
Posts: 10
Hi all,

I'v in trouble to link together two hierarchies at the top level (security). i've successed for most cases but some still fail.

I've a hierarcy of domain entities whose derived from a generic SecuredClass annotated with @MappedSuperclass (so not an entity).
This SecuredClass has a one to many to an abstract entity SecurityClass.
This abstract security class has the backward many to one link to a default SecuredClass (because ManyToOne needs Entity) : ItemClass.
Then for all first childre of SecuredClass we can create a New specific SecurityClass with the correspondant field... Ok I know that's really tricky. I use annotation for that :

Code:
@MappedSuperclass
SecuredClass {
    @OneToMany(
                        mappedBy = "securedObject",
         fetch = FetchType.LAZY,
         targetEntity = SecurityClass.class)
    SecurityClass rights;
}

//This is one secured entity
@Entity
ItemClass extends SecuredClass {
}

//This is another secured entity
@Entity
PropertyClass extends SecuredClass {
}

========security part==========

@Entity //[b]manyToOne needs Entity in SecuredClass[/b]
abstract SecurityClass {
   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "ITEM", nullable = true)
        //Note [b]NO FK [/b](schema manually managed)
        //Note [b]ItemClass[/b] entity is the default entity
        //Note the [b]private[/b]
   private ItemClass securedObject = null;

//ACCESSOR
}

@Entity
ItemSecurityClass extends SecurityClass {}

@Entity
PropertySecurityClass extends SecurityClass {
   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "PROPERTY", nullable = true)
        //Note [b]NO FK [/b](schema manually managed)
        //Note [b]ItemClass[/b] entity is the default entity
        //Note the [b]private[/b]
   private PropertyClass securedObject;

//ACCESSOR => OVERRIDEN
}


So, I told it... it's tricky. but it works in most cases. Missing ones are :
1] When creating and persiting a PropertySecurityClass the Tuplizer will add the PropertyClass.id to both the PROPERTY and ITEM columns
2] When PropertySecurityClasses have to be retrieved Lazily, Hibernate throw a System exception "setter" saying that he can set the 'securedObject' on a PropertySecurityClass instance.

Those problems occurs because :
1] both the SecurityClass.securedObject and PropertySecurityClass.securedObject are mapped on the same object (PropertyGetter) => the value are added at both places
2] it's the same kind of problem, hibernate wants to set both the SecurityClass.securedObject and PropertySecurityClass.securedObject with the propertyClass instance he has.

So it seems either to be a "bug" in hibernate to not support the private field overrided or this particular tricky schema isn't permitted.

What do think ? Could I reach my goal using my own Tuplizer ?

thanks very much in advance ^^

PS : sorry for the bad english[/b]


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.