persistence@glassfish.java.net

Re: How to specify a custom id generator

From: Marina Vatkina <Marina.Vatkina_at_Sun.COM>
Date: Fri, 15 Jun 2007 12:00:57 -0700

Looks like this mail never made it to the alias.

-marina

> Hi.
>
> I do not believe that workaround will work for me. Let me explain why.
>
> I am working on the HyperJAXB3 project which generates my annotated
> pojos from xsd. My test case for HyperJAXB3 involves XML documents that
> conform to a schema that requires id attribute of a XML complexType to
> be a valid URN ( e.g. urn:uuid:xxx ). The value for id attribute is in an
> XML document and not in a pojo. HyperJAXB3 implementation needs some way
> to configure HyperJAXB3 binding customization such that a underlying
> persistence provider can be told to use the id attribute provided by the
> XML document as primary key when persisting the XMl document.
>
> Perhaps Aleksei may be able to describe the situation better?
>
>
> I guess folks are right, there are no custom id generators in the spec.
>
> But I think the problem can be solved anyway. We can assign the Id in the constructore, for instance. Or implement a callback method (like @PrePersist and so on) to assign the id if it is missing.
>
> In your case, I think, you simply want to use the already assigned value. When you use the <hj:id/> customization to mark an attribute as an id, HJ3 does not generate an additional property, it reuses the attribute. Therefore it IS in both XML and POJO.
> I guess we simply need to avoid @GeneratedValue annotation in this case.
>
> Thank you guys for help.
>
> Bye.
> /lexi