You cannot use load or get. You should use a HQL query e.g. session.createQuery("from User where username=:name").setString("name", name).
You can also declare your username field as natural id. However you cannot do this using annotations (only in the next version) only with hibernate.classes.xml. In addition as I remember there are two outstanding bugs in Hibernate core related to immutable natural ids, one was fixed in the very last version.
The advantage of immutable natural ids over a simple index is that it is cached. You have to use the criteria queries api for this, see section 15.9. Queries by natural identifier in the reference for more information.
|