-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Hibernate dynamic models with level 2 cache gives exception.
PostPosted: Tue Apr 26, 2016 1:28 am 
Newbie

Joined: Tue Apr 26, 2016 12:32 am
Posts: 2
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.


Top
 Profile  
 
 Post subject: Re: Hibernate dynamic models with level 2 cache gives exception.
PostPosted: Tue Apr 26, 2016 2:10 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Try it like this:

Code:
<hibernate-mapping>

    <class entity-name="Customer">
   
        <cache usage="read-write"> 
   
        <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>


Top
 Profile  
 
 Post subject: Re: Hibernate dynamic models with level 2 cache gives exception.
PostPosted: Tue Apr 26, 2016 9:05 am 
Newbie

Joined: Tue Apr 26, 2016 12:32 am
Posts: 2
I had already worked it out. Anyways, thanks for your response.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.