-->
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: Is there way to mark method not initiazlie Proxy
PostPosted: Sun Feb 22, 2009 5:30 am 
Newbie

Joined: Thu Jul 24, 2008 9:08 am
Posts: 3
Location: Poland
Hi All !

Hibernate uses generating proxy in some cases. And proxy is initialized if invoked method is other than id (equals and hash are ovveride often)

http://www.hibernate.org/hib_docs/v3/reference/en-US/html/performance.html#performance-fetching-proxies

Quote:
Certain operations do not require proxy initialization
* equals(), if the persistent class does not override equals()
* hashCode(), if the persistent class does not override hashCode()
* The identifier getter method


But sometimes designer of model know that invoking specific method doesn't have to initialize proxy, eg instance of or generic stringTo.

http://www.hibernate.org/280.html

Code:
    public boolean instanceOf(Class<?> otherClass) { return otherClass.isAssignableFrom(getPoliticianClass()); }
    public Class<?> getPoliticianClass() { return Politician.class; }
    public Class<?> getPoliticianClass() { return Democrat.class; }
    Politician politician = ...; // code to find your (s)elected politician
    if (politician.instanceOf(Democrat.class) {
        // politician is a democrat
        Democrat democrat = (Democrat) session.get(Democrat.class,
politician.getId())
        // Use your democrat.
    }


if using "x instance of Democrat" it doesnt initialize proxy but x.instanceOf(Democrat.class) initialize proxy which isn't required. It would be great to mark method some annotation like @NotInitializeProxy.

Other case which I meet is generic stringTo

Code:
interface IDescription {
   String description();
}

@Entity
class Entity implments IDescription {
  getId(); // not initialize proxy
  String description() { return getClass.getName() + ":" + getId() } // unfortunately initialize proxy
}

genericStringTo {
[...] if (false == Hibernate.isInitizlied(field)) { respond.name("fielndName").value(field.description()) }
[...]
}


Also, method "description" would be marked as @NotInitializeProxy.

Is hibernate support that cases or maybe could be support in future this ?

_________________
Kamil Demecki
Jee/Python Developer
skajotde.googlepages.com


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.