简体   繁体   中英

Hibernate — Load a record off arbitrary field

I've had the opportunity to rework a good deal of old, poorly maintained perl scripts from a department library into a newer Java design, which hopefully should be more maintainable. Originally, this library did a number of things relating to our Active Directory instance, including things like looking for and reporting on new users, keeping track of which users we knew about, etc.

The next functionality to replicate is the ability to store simple user information in a database -- things like names, employee IDs and account names, nothing too complex. Because I generally don't enjoy JDBC, and I had the opportunity to expand my horizons a bit, so I decided to poke at Hibernate. I know it's very likely overkill for what I'm doing with this application, but I figured that it was a good learning opportunity.

The issue that I have is fairly simple. I've got creating new persistent objects down, that's no sweat. Where I hit a speed bump is in retrieving those objects from the database using Hibernate. I can load the class by its built in ID, but I don't see an option to load on anything else, and needless to say, there isn't an option to save the database's user ID into AD itself. I'm wondering if someone can provide a bit of insight on how to load already-seen users from the database without the User ID; a tutorial or link would be fine. I've tried reading the Hibernate documentation itself, but it's massive, and the vast majority doesn't apply to what I'm actually doing.

Thanks.

Your best bet is to read section 10.4 of the hibernate reference guide on HQL queries. Although you can use the Hibernate Criteria API to formulate queries, HQL is probably the easier to grasp IMHO. In a nutshell, you can formulate queries using the Hibernate Session and using the persistent object's attributes for restriction criteria.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM