users@jaxb.java.net

How can I persist the content of "xsd:any" tag ?

From: bastral <baptistebesson_at_yahoo.fr>
Date: Mon, 2 Jul 2007 15:04:18 -0700 (PDT)

Hello,

Using wsimport I generated a class from the following xsd type:

[code]
<xsd:complexType name="MDVendorExtensions_T">
   <xsd:sequence>
      <xsd:any namespace="##any" processContents="lax" minOccurs="0"
maxOccurs="unbounded"/>
    </xsd:sequence>
</xsd:complexType>
[/code]


The class generated was :

[code]
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "MDVendorExtensions_T", propOrder = {
    "any"
})
public class MDVendorExtensionsT {
 
    @XmlAnyElement(lax = true)
    protected List any;
   
public List getAny() {
        if (any == null) {
            any = new ArrayList();
        }
        return this.any;
   }
}
[/code]


Then I would like to map MDVendorExtensionT into a database using ejb3
annotations. As I can't map a List I created an entity bean E just to wrap
Object. So after adding persitent annotations:

[code]
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "MDVendorExtensions_T", propOrder = {
    "any"
})
@Entity
@Table(name = "MDV")
public class MDVendorExtensionsT implements Serializable{
    @Id
    private Long id;
    @XmlAnyElement(lax = true)
    @OneToMany(cascade={CascadeType.ALL})
    protected List<E> any;
....
[/code]


with E containing just an id:

[code]
@Entity
public class E implements Serializable {
@Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
..
[/code]


If I have an xml file which contains an element vendorExtension that
validate the xsd:any type defined above:

[code]
<root>
<vendorExtension>
<element1>first element<element1>
<element2> <element2_1> ....</element2_1></element2>
...
<vendorExtension>
</root>
[/code]


My question is : how can I store the content of vendorExtension element into
the database. There can be as many element as the user want under this
element and if I try this code with just

[code]
<vendorExtension><element1>first Element <element1></vendorExtension>
[/code]

I get a

[code]
java.lang.IllegalArgumentException: Object: [element1: null] is not a known
entity type.
[/code]


At first I wanted to store the content of vendorExtension as a string (I
don't know how to do it either) but I think it's not a good solution if the
content is very big

Thank you.
-- 
View this message in context: http://www.nabble.com/How-can-I-persist-the-content-of-%22xsd%3Aany%22-tag---tf4015177.html#a11402872
Sent from the java.net - jaxb users mailing list archive at Nabble.com.