From: Max R. A. <max...@jb...> - 2006-07-06 11:22:24
|
> Hi I am sending this again could anyone tell me if this might be usefu= l > to the communitY? I would like to help if it would be. From the look of it looks like something that is "evil" since that code= will not do what it actually states. Why not simply generate a MyClassProperties class that list the property= = names and use that to refer to some compiletime safe name ? Sounds much simpler and portable imo. /max > > Thanks, > > > > > Dhanji, > > > > > ________________________________ > > From: hib...@li... > [mailto:hib...@li...] On Behalf Of > Dhananjay Prasanna > Sent: Wednesday, 28 June 2006 11:31 AM > To: hib...@li... > Subject: [Hibernate] (semi) Entity-type safe criteria queries > > > > > Hi All > > > > > I am writing to ask about type-safety (in a very rudimentary way) in > Criteria queries. I know there has been some discussion around this > topic with the SODA group and others, but I am curious if this has bee= n > considered for Hibernate. > > Basically, instead of using the system: > > > > > Criteria q =3D session.createCriteriaQuery(MyClass.class); > > q.add ( Restriction.eq( "propName", value) ); > > > > > which is unsafe to the entity-type under query, would it be possible t= o > do something like: > > > > > Criteria q =3D session.createSafeCriteriaQuery(MyClass.class); > > MyClass my =3D q.obtainQueryable(MyClass.class); > > q.add( Restriction.eq( my.getPropName(), value )); > > > > > The special instance "my" would contain proxies or bytecode-instrument= ed > properties that would return the appropriate mapped property name to t= he > Criterion. Apart from being safe to the Entity type under consideratio= n > (statically) and its properties, this approach has the added advantage= > of bringing criteria queries into an IDE's refactoring scope. > > > > > The cons are the added performance hit of proxies or bytecode > manipulation, and the extra step in obtaining a reference to a queryab= le > entity. However I believe the pros far outweigh this, as my own projec= t > occasionally undergoes property-refactoring and has a LOT of > similarly-named properties across classes (too many for a sane person = to > discriminate on sight!). > > Anyway, I thought I would bring it up-Im sure typesafety has been > discussed before so please forgive me if this is a rehash. I'm also > happy to contribute an implementation of this if you guys find it wort= h > adding. > > > > > Thanks!! > > > > > Dhanji. > > This correspondence is for the named persons only. > > It may contain confidential or privileged information or both. > > No confidentiality or privilege is waived or lost by any mis > transmission. > > If you receive this correspondence in error please delete it from your= > system immediately and notify the sender. > > You must not disclose, copy or relay on any part of this correspondenc= e, > if you are not the intended recipient. > > Any opinions expressed in this message are those of the individual > sender except where the sender expressly, > > and with the authority, states them to be the opinions of the Departme= nt > of Emergency Services, Queensland. > > > > > This correspondence is for the named persons only. > > It may contain confidential or privileged information or both. > > No confidentiality or privilege is waived or lost by any mis = > transmission. > > If you receive this correspondence in error please delete it from your= = > system immediately and notify the sender. > > You must not disclose, copy or relay on any part of this correspondenc= e, = > if you are not the intended recipient. > > Any opinions expressed in this message are those of the individual = > sender except where the sender expressly, > > and with the authority, states them to be the opinions of the Departme= nt = > of Emergency Services, Queensland. -- = -- Max Rydahl Andersen callto://max.rydahl.andersen Hibernate ma...@hi... http://hibernate.org JBoss Inc max...@jb... |