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!