Hibernate does not force a relationship between the id and the primary key in the table. It's a very very good idea to have the id and primary key be the same, but theoretically you can work around it. (In fact hibernate doesn't even force you to have a primary key at all, though it does force you to have an id) Just avoiding a little HQL code or an extra factory method or two would not qualify, in my mind, as a sufficient reason to break the id/primary key relationship.
But if you think it's best: just use assigned as your id generator strategy and set the id to the appropriate value, which will have to be unique per row. For your real DB primary key, which will presumably be DB-generated (default value in the DB, identity type column, whatever), make sure that you make it a read-only column in your mapping, using insert="false" and update="false". You could generate the primary key yourself in your save logic, and leave insert="true", but then you're beginning to delve into the depths of DB hackery.
Again, let me urge you to go with the HQL query options, or at least use Criteria. session.get(X.class, id) isn't that much easier than createQuery("X where column = :value").setString("value").uniqueResult().
|