I am using dynamic models for entity creation and i need to provide caching over it. But i am getting exception "Unable to read XML"
Step 1. Creating Dynamic model entity. Runs fine. I can save update using this entity.
<hibernate-mapping>
<class entity-name="Customer">
<id name="id" type="long" column="ID"> <generator class="identity"/> </id>
<property name="name" column="NAME" type="string"/>
<property name="address" column="ADDRESS" type="string"/>
</class> </hibernate-mapping> The entity is created at run time.
Step 2. Specify <property name="hbm2ddl.auto">update</property> in cfg xml. Runs fine, it creates the table as well if it does not exists.
3. Now i need to provide 2nd level cache on this entity but first i do not find any documentation for it straightaway. Second specifying <cache usage="read-write" /> in dynamic model entity gives exception as below. (Creating entity classes with annotations instead of dynamic models runs fine without exceptions, already tested)
Exception stack trace:
org.hibernate.InvalidMappingException: Unable to read XML at org.hibernate.internal.util.xml.MappingReader.legacyReadMappingDocument(MappingReader.java:375) at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:304) at org.hibernate.cfg.Configuration.add(Configuration.java:516) at org.hibernate.cfg.Configuration.add(Configuration.java:512) at org.hibernate.cfg.Configuration.add(Configuration.java:686) at org.hibernate.cfg.Configuration.addResource(Configuration.java:769) at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2255) at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2227) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2207) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2160) at org.hibernate.cfg.Configuration.configure(Configuration.java:2075) at util.HibernateUtil.buildSessionFactory(HibernateUtil.java:19) at util.HibernateUtil.getSessionFactory(HibernateUtil.java:37) at main.DynamicMain.main(DynamicMain.java:21) Caused by: org.xml.sax.SAXParseException; lineNumber: 44; columnNumber: 13; The content of element type "class" must match "(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,fetch-profile*,resultset*,(query|sql-query)*)". at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
I need help in resolving this. If any extra code snippet required then let me know.
|