I'm getting org.xml.sax.SAXParseException's when trying to map a one-to-one relation in JPA
Everything is working fine until I change from
<transient name="testCase"/>
to:
<attributes>
..
<one-to-one name="testCase">
<join-column name="test_case_id"/>
</one-to-one>
..
</attributes>
Gives error:
Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'one-to-one'. One of '{"http://java.sun.com/xml/ns/persistence/orm":many-to-many, "http://java.sun.com/xml/ns/persistence/orm":embedded, "http://java.sun.com/xml/ns/persistence/orm":transient}' is expected.
I don't understand what the exception message means. Why is these expected for this?
Your orm.xml was not valid according to it's XML Schema. The problem was that the element 'one-to-one' is part of a sequence, which means that the contained elements MUST respect the defined order.
An abstract of the Schema:
<xsd:complexType name="attributes">
<xsd:sequence>
...
<xsd:element name="basic" .../>
<xsd:element name="version" .../>
<xsd:element name="many-to-one" .../>
<xsd:element name="one-to-many" .../>
<xsd:element name="one-to-one" .../>
<xsd:element name="many-to-many" .../>
...
</xsd:sequence>
</xsd:complexType>
see the whole Schema at enter link description here
I found the problem. I moved the one-to-one section so it was before the many-to-many section. Don't know why this happened. The two sections does not have anything in common.
Related
I have a SOAP URL with one of the input parameters of enumerated type as below. With SOAPUI I'm just able to remove the ? mark and able to execute the request successfully. <urn:Comm_Source></urn:Comm_Source>
I created client code using wsimport and it creates the input method parameter as CommSourceType object. If I pass null for this value the web service fails.
<xsd:element maxOccurs="1" minOccurs="0" name="Comm_Source" nillable="false" type="s0:Comm_SourceType"/>
There is a lack of information for the complete answer (eg the whole wsdl/xsd or what means: If I pass null for this value the web service fails.).
In general:
null is not the same as an empty string.
<urn:Comm_Source></urn:Comm_Source> - is an empty string
<urn:Comm_Source xsi:nil="true" /> - is a null value (xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance")
the specified element <xsd:element maxOccurs="1" minOccurs="0" name="Comm_Source" nillable="false" type="s0:Comm_SourceType" /> does not support null because there is nillable="false".
The element can either be omitted or an empty string can be written in it.
When I define the fields of a contract in XSD I define a list field with maxOccurs= and minOccurs>0.
Can i declare the XSD in such a way that when the request is received the fields with occurs have occurance number?
e.g.
I hope i make my self clear.
<xsd:complexType name="FieldNameType">
<xsd:sequence>
<xsd:element name="FieldName" type="FieldNameType" minOccurs="1" maxOccurs="8"/>
</xsd:sequence>
</xsd:complexType>
and when the request is send i get something like:
<FieldName_1></FieldName_1>
<FieldName_2></FieldName_2>
<FieldName_3></FieldName_3>
Thanks in advance!
I found a work-around! As i saw i can iterate through the same nodes in an XSLT file.
I'm working on a SOAP webservice which features many inputfields using enumeration restrictions.
These enumerations are much like an HTML select/option setup; I expect a certain value to be returned but the label of that value should be exposed using the WSDL as well.
An example: the client wishes to add an insurance policy regarding his/her house and thus needs to specify the type of building involved.
<xsd:restriction base="xsd:string">
<xsd:enumeration value="00001" />
<xsd:enumeration value="00002" />
<xsd:enumeration value="00003" />
</xsd:restriction>
However, the client does not yet understand what these values 1, 2 and 3 are. So, something like this:
<xsd:restriction base="xsd:string">
<xsd:enumeration value="00001" label="Brick and mortar" />
<xsd:enumeration value="00002" label="Straw" />
<xsd:enumeration value="00003" label="Aircastle" />
</xsd:restriction>
would be great for the client to be used to display these labels to the consumer.
Is there any standard WSDL annotation/syntax for this construction?
Is there any standard WSDL annotation/syntax for this construction?
I'm afraid not. The XML Schema enumeration is used to constrain a value to be within a specified set of possible values. When your client sends you the request, the element with the restriction type will only be allowed to have (in your case) a value of 00001, 00002 or 00003 or it won't be valid.
The restriction only specifies the values, you can't add labels. You could at best add an <annotation> but that would be just documentation. In the client UI, it would be the responsibility of each client to say that 00001 is actually "Brick and mortar" and that 00002 is "Straw" etc.
If you don't want to do that, and instead want to also return labels, then you need a slightly more complex object, maybe something like this:
<option>
<key>00001</key>
<label>Brick and mortar</label>
</option>
You provide a label and you restrict the key with a schema like:
<xsd:simpleType name="ValuesType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="00001" />
<xsd:enumeration value="00002" />
<xsd:enumeration value="00003" />
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="OptionType">
<xsd:sequence>
<xsd:element name="key" type="ValuesType" />
<xsd:element name="label" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
You can return a list of options to the clients and they can present it in the interface with key as value and label as the text of options in <select> inputs, while on the request you will get back the selected value (i.e. the selected key).
I want to implement lucene based hibernate search in my assignment. For generating domain objects I am using HyperJaxb3.
I want #Indexed annotation to be added during domain object creation using HyperJaxb.
I tried googling for this, but unable to find solutions.
Any pointer in this regard will be of great help.
Annotate plugin is the right answer. See this example.
This is how it looks in schema:
....
xmlns:hs="http://annox.dev.java.net/org.hibernate.search.annotations"
...
<xsd:complexType name="USAddress">
<xsd:sequence>
<xsd:element name="name" type="xsd:string">
<xsd:annotation>
<xsd:appinfo>
<annox:annotate>
<hs:FieldBridge impl="org.jvnet.hyperjaxb3.ejb.tests.annox.Items">
<params>
<hs:Parameter name="foo" value="bar"/>
</params>
</hs:FieldBridge>
</annox:annotate>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="street" type="xsd:string"/>
<xsd:element name="city" type="xsd:string"/>
<xsd:element name="state" type="xsd:string"/>
<xsd:element name="zip" type="xsd:decimal"/>
</xsd:sequence>
<xsd:attribute name="country" type="xsd:NMTOKEN" fixed="US"/>
</xsd:complexType>
You can also use extra binding files (see the example).
I use Hyperjaxb3 to generate JPA entities from XSD schema. I have a xsd:string type that I want to use for description text (text area in the UI):
<xsd:complexType name="Description">
<xsd:simpleContent>
<xsd:extension base="**xsd:string**">
<xsd:attribute name="abc" type="xsd:NCName" use="optional" />
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
Hyperjaxb3 generates class (entity) Description with attribute value, annotated like this:
#Basic
#Column(name = "VALUE_", **length = 255**)
public String getValue() {
return value;
}
The questions I have:
I saw that if I put xsd:maxLength restriction on xsd:simpleType, JPA #Column.length has the value of maxLength. How can I set xsd:rescriction on xsd:simpleContent that is xsd:extension of xsd:string? Do I have to define a complexType with xsd:resctriction that I will extend? And if yes, will Hyperjaxb generate #Column.length by my restriction. I tried following:
<xsd:simpleType name="DescriptionParent">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="4096" />
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="Description">
<xsd:simpleContent>
<xsd:extension base="DescriptionParent">
<xsd:attribute name="abc" type="xsd:NCName" use="optional" />
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
But the JPA column length is still 255.
Is it also possible to set in my JAXB customization (*.xjb file) the lenght of the column for given type (somehow let hyperjaxb know that this is the orm I want to use for my specific type)? Or is it totally out of the way and xsd:maxLength should be used (above) I managed to set it globally for Hyperjaxb customization:
Thanks for your help.
Second question: yes, you can configure global type mappings for simple types.
See Per-type customization for single properties.
First question: it seems to be a bug/missing feature, please file an issue here.