-
1. Re: EntityHome and Primay Key value assignment for new recor
terryb Oct 10, 2007 12:36 PM (in response to terryb)I found my mistake, I wasn't using the right instance.
the following fixed the problem 1.
@Override
public String persist() {
if (Strings.isNull(getInstance().getId()) && !this.isManaged()) {
KeyGenerator keyGen = (KeyGenerator) Component.getInstance (KeyGenerator.class, true);
getInstance().setId(keyGen.getKey(Constant.Database.KeySuffix.ADMIN));
}
return super.persist();
}
Any clue to my question 2 will be appreciated. -
2. Re: EntityHome and Primay Key value assignment for new recor
swd847 Oct 10, 2007 6:35 PM (in response to terryb)I am to 100% sure what you mean, by q2 but I think you want to look up the section in the hibernate entityManager docs on event listeners. I think you could set a PrePersist listener on you keygen component, and this would acomplish what you are after, I am not sure though.
-
3. Re: EntityHome and Primay Key value assignment for new recor
terryb Oct 11, 2007 12:41 AM (in response to terryb)I tried @PrePersist but got struck with popular hibernate bug... Id must be be assigned manually..., it's to do with hibernate doing validations before invoking PrePersist I think...
The bug is fixed in latest hibernate GA release, but I am not sure what else will break if i use it with Redhat Developer Beta 1.
So as a workaround, Im keeping my code in MyEntityHome for now, as above.
Q2. I was trying to use my generated Id as a default value for the jsf h:inputHidden tag. The tage is bound to the ID property of the entity bean. So I thought that way it will work automatically, as JSF will assign value in hidden bound control to the backing entity bean.
I just couldn't figure out how to have h:inputHidden bound to the entity property and at the same time make it use my generate Id as a default value.
h:inputHidden id="code" required="true" size="50" maxlength="50" value="#{securityRoleHome.instance.id}"
/h:inputHidden