-->
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: How to parameterize collection property on model object?
PostPosted: Wed Mar 07, 2007 10:03 pm 
Newbie

Joined: Sat Jan 06, 2007 3:46 pm
Posts: 15
Hibernate version: 3.2.2

Mapping documents: annotations, 3.2.1

Code between sessionFactory.openSession() and session.close():

Name and version of the database you are using: MySQL 5.0.x

The generated SQL (show_sql=true):

Code:
Hibernate: select mdfiles0_.mGroupId as mGroupId2_, mdfiles0_.mId as mId2_, mdfiles0_.mId as mId1_1_, mdfiles0_.mGroupId as mGroupId1_1_, mdfiles0_.mDerivedFromId as mDerived3_1_1_, mdfiles0_.mLang as mLang1_1_, mdfiles0_.mPath as mPath1_1_, mdfiles0_.mName as mName1_1_, sourcefile1_.mId as mId1_0_, sourcefile1_.mGroupId as mGroupId1_0_, sourcefile1_.mDerivedFromId as mDerived3_1_0_, sourcefile1_.mLang as mLang1_0_, sourcefile1_.mPath as mPath1_0_, sourcefile1_.mName as mName1_0_ from SourceFile mdfiles0_ left outer join SourceFile sourcefile1_ on mdfiles0_.mDerivedFromId=sourcefile1_.mId where  ( mdfiles0_.mLang = 'D')  and mdfiles0_.mGroupId=? order by mdfiles0_.mName asc


I've succeeded in getting a basic constrained one-to-many association set up. You can see the code here.

I've got a method

Code:
List<SourceFile> getFiles()


that's properly mapped, and a method

Code:
List<SourceFile> getDFiles()


that's also successfully mapped with an @Where annotation to constrain the resulting collection. All of this works well.

Now, I want to add a method

Code:
List<SourceFile> getFilesBeginningWith(String inPrefix)


I don't see any way to do this without having the session available and using the Hibernate API. I don't mind doing this, but I feel like I've been told this is a bad approach. I'm not concerned with tying myself to Hibernate.

I am using Spring. I don't know if that can help me to ensure that each new model object instantiated by Hibernate is provided with a session for use by its methods (the current thread's session). I can implement that myself, but it seems that I should be able to get an injection.

Can anyone tell me where to look for examples or instructions, or suggest an alternative approach? The Hibernate book is light in the area of specialized associations. Thanks!


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.