I'm trying to embed multiple instances of the same complextype into a single entity, which does not seem to work unless I define a new complextype for each instance. As far as I can make up until now, this is probably because of the default hyperjaxb3 naming strategy. Is there a way to change the default hyperjaxb3 naming strategy via annotations (similar to setting the id strategy, for example) rather than adding code to the plugin itself? Thanks, Frederik
Asked
Active
Viewed 1,639 times
1 Answers
1
It would be much easier if you provide an example of what you're trying to do: schema, generated annotations and what you'd like to have generated instead.
Here's what I have in one of the test projects. Schema:
<xs:element name="a" type="aType"/>
<xs:complexType name="aType">
<xs:sequence>
<xs:element name="b0" type="bType" minOccurs="0"/>
<xs:element name="b1" type="bType" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="bType">
<xs:annotation>
<xs:appinfo>
<hj:embeddable/>
</xs:appinfo>
</xs:annotation>
<xs:sequence>
<xs:element name="c" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="999"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="d" type="xs:int" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
Generates:
@Embedded
@AttributeOverrides({
@AttributeOverride(name = "c", column = @Column(name = "B0_C", length = 999)),
@AttributeOverride(name = "d", column = @Column(name = "B0_D", precision = 10, scale = 0))
})
public BType getB0() {
return b0;
}
@Embedded
@AttributeOverrides({
@AttributeOverride(name = "c", column = @Column(name = "B1_C", length = 999)),
@AttributeOverride(name = "d", column = @Column(name = "B1_D", precision = 10, scale = 0))
})
public BType getB1() {
return b1;
}
I don't see naming collisions.
UPDATE
Here's some links about customization of naming:
Check this guide:
http://confluence.highsource.org/display/HJ3/Customization+Guide
Here's a test project which demonstrates some of those features:
http://java.net/projects/hj3/sources/svn/show/trunk/ejb/tests/cu-one
You can also write and configure your own naming strategy:
http://java.net/projects/hj3/sources/svn/show/trunk/ejb/tests/custom-naming

lexicore
- 42,748
- 17
- 132
- 221
-
Correct, I guess I got confused when the hj3 output was not what I expected, on a multi-level embedded complexType. In the example you provide, adding a 3rd embeddable complextype in bType marks it as @Transient in class BType, which seems a bit strange... How are nested embeddables handled in hj3? – Frederik Jun 26 '11 at 21:56
-
JPA 1 does not support nested embeddables, so if yo run HJ3 in JPA 1 mode then nested embeddables are made transient. JPA 2 however supports nested embeddables and HJ3 in JPA 2 mode (available in current 0.5.6-SNAPSHOT) also supports it. See this test project: http://java.net/projects/hj3/sources/svn/show/trunk/ejb/tests/embeddable-jpa2 The functionality is very new, however, so there might be some problems. – lexicore Jun 27 '11 at 06:49
-
Thanks, I'll give the snapshot a go. – Frederik Jun 27 '11 at 22:41
-
Snapshot works fine - thanks for that! Is there any way to turn off the reserved names check? – Frederik Jul 02 '11 at 12:28
-
Ok. Any chance to override it or force the name in the annotation? – Frederik Jul 02 '11 at 15:33
-
Yes, via customizations. Post your case to users@hyperjaxb.java.net, I'll take a look. – lexicore Jul 02 '11 at 20:18
-
Me neither. Are you a subscriber? Please forward your mail to valikov()gmx.net. – lexicore Jul 04 '11 at 19:46
-
Yes, I've got it. I'll reply when I get to it. – lexicore Jul 06 '11 at 19:27