How to insert binary XML into Oracle table?

Viewed 36

I could not find a simple example binary xml + JPA. The Oracle documentation only shows excerpts of code.

I have Entity

@Entity
public class XMLentity {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Lob
    @Column(name = "MYXML", columnDefinition = "XMLType")
    private byte[] xml;

I have Entity Fruit

@XmlAccessorType(XmlAccessType.FIELD)
public class Fruit {

    @XmlAttribute
    int id;

    String name;

    String price;

and parser

public class Demo {

    public static void main(String[] args) throws Exception {
        JAXBContext jc = JAXBContext.newInstance(Fruit.class);

        Unmarshaller unmarshaller = jc.createUnmarshaller();
        File xml = new File("fruit.xml");
        Fruit fruit = (Fruit) unmarshaller.unmarshal(xml);

        Marshaller marshaller = jc.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(fruit, System.out);
    }

}

How to insert fruit into Oracle table? P.S. I want to follow the Oracle recommendation: Starting with Oracle Database 12c Release 1 (12.1.0.1), the unstructured (CLOB) storage model for XMLType is deprecated. Use binary XML storage instead.

0 Answers
Related