You could try instantiating an
org.hibernate.id.TableGenerator object directly; but doing it in your object design is probably better.
First, make a new class
VerifiedMark:
Code:
class VerifiedMark { // might not need to be public
int id;
}
and a mapping for it:
Code:
<class name="VerifiedMark" >
<id access="field" ><generator class="native" /></id>
</class>
Now add a property to your "Review" class, and modify the setter for the "status" property:
Code:
.....
private VerifiedMark verifiedMark;
public void setStatus(String status) {
this.status = status;
if ("Verified".equals(status) && verifiedMark==null)
verifiedMark = new VerifiedMark();
}
public int getVerifiedId() {
if (verifiedMark==null) return 0; else return verifiedMark.id;
}
......
I think you would also add a
one-to-one mapping from Review to VerifiedMark:
Code:
<one-to-one name="verifiedMark" access="field" class="...VerifiedMark" />
On MySQL, Hibernate will create one extra table,
verifiedmark, with one int primary key auto_increment column. On some other databases Hibernate would use a sequence instead.