-->
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.  [ 4 posts ] 
Author Message
 Post subject: Named SQL Query in the Mapping Files
PostPosted: Wed Nov 16, 2005 2:09 pm 
Newbie

Joined: Wed Nov 16, 2005 1:55 pm
Posts: 12
Hi all, I am having a problem creating a named sql query in a
hibernate mapping file. If i take out the <sql-query> element then there is
a different error which i have posted below the original exception output below..

i have searched but i cannot find any mapping examples that include
named queries.. can anyone help me out here.. thanks

jazz


Hibernate version:
3.0.5

Mapping documents:
Users.hbm.xml
Code:
<hibernate-mapping >

    <class name="com.insaini.publogs.hibernate.tables.Users" table="users">
        <id name="id" column="id" type="java.lang.Integer">
            <generator class="native"/>
        </id>

        <property name="name" column="name" type="java.lang.String"  not-null="true" />
        <property name="pass" column="pass" type="java.lang.String"  not-null="true" />

        <set name="roles" inverse="true">
           <key column="id" not-null="true"/>
           <many-to-many column="id" class="Roles"/>
        </set>
       


      <sql-query name="user.by.name">
             <return alias="user" class="Users"/>
             SELECT u.id, u.pass
             FROM users u
             WHERE u.name = ':name'
      </sql-query>
                 
    </class>
   
</hibernate-mapping>


Full stack trace of any exception that occurs: (with <sql-query> tag)
ERROR main org.hibernate.util.XMLHelper - Error parsing XML: XML InputStream(96) The content of element type "class" must match "(meta*,subselect?,cache?,synchronize*,comment?,(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|query-list)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*)".
ERROR main com.insaini.publogs.struts.HibernatePlugIn - Exception while initializing Hibernate.
ERROR main com.insaini.publogs.struts.HibernatePlugIn - Rethrowing exception...
org.hibernate.MappingException: Error reading resource: Users.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:452)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1263)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1235)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1217)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1184)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1127)
at com.insaini.publogs.struts.HibernatePlugIn.initHibernate(HibernatePlugIn.java:117)
at com.insaini.publogs.struts.HibernatePlugIn.init(HibernatePlugIn.java:95)
at org.apache.struts.action.ActionServlet.initModulePlugIns(ActionServlet.java:869)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:336)
at javax.servlet.GenericServlet.init(GenericServlet.java:211)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1091)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:925)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3880)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4141)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:759)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:739)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:603)
at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:535)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:470)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1118)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:310)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1020)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1012)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
at org.apache.catalina.core.StandardService.start(StandardService.java:450)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:680)
at org.apache.catalina.startup.Catalina.start(Catalina.java:536)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:275)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)

Full stack trace of any exception that occurs: (without <sql-query> tag)
org.hibernate.MappingException: Association references unmapped class: Blogs
at org.hibernate.cfg.HbmBinder.bindCollectionSecondPass(HbmBinder.java:2036)
at org.hibernate.cfg.HbmBinder$CollectionSecondPass.secondPass(HbmBinder.java:2497)
at org.hibernate.cfg.HbmBinder$SecondPass.doSecondPass(HbmBinder.java:2468)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:884)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:999)
at com.insaini.publogs.struts.HibernatePlugIn.initHibernate(HibernatePlugIn.java:118)
at com.insaini.publogs.struts.HibernatePlugIn.init(HibernatePlugIn.java:95)
at org.apache.struts.action.ActionServlet.initModulePlugIns(ActionServlet.java:869)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:336)
at javax.servlet.GenericServlet.init(GenericServlet.java:211)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1091)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:925)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3880)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4141)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:759)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:739)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:603)
at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:535)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:470)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1118)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:310)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1020)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1012)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
at org.apache.catalina.core.StandardService.start(StandardService.java:450)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:680)
at org.apache.catalina.startup.Catalina.start(Catalina.java:536)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:275)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)

Name and version of the database you are using:
MySQL 5.0.15


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 16, 2005 2:19 pm 
Newbie

Joined: Wed Nov 16, 2005 1:55 pm
Posts: 12
I think I know the reason to the second exception error above

my Blogs table has a one-to-many relationship with it-self.. is this possible?

here is my Blogs mapping file

Blogs.hbm.xml
Code:
<hibernate-mapping>

    <class name="com.insaini.publogs.hibernate.tables.Blogs" table="blogs">
        <id name="id" column="id" type="java.lang.Integer">
            <generator class="native"/>
        </id>

        <property name="name" column="name" type="java.lang.String"  not-null="true" />
        <property name="body" column="body" type="java.lang.String"  not-null="true" />
        <property name="numviewed" column="numViewed" type="java.lang.Integer"  not-null="true" />
        <property name="status" column="status" type="java.lang.Integer" />
        <property name="datecreated" column="dateCreated" type="java.util.Date"  not-null="true" />
        <property name="datemodified" column="dateModified" type="java.util.Date"  not-null="true" />
        <property name="userid" column="userId" type="java.lang.Integer"  not-null="true" />
        <property name="topicid" column="topicId" type="java.lang.Integer" />
        <property name="blogid" column="blogId" type="java.lang.Integer" />
           
       <many-to-one name="userid" column="userId" not-null="true" />           
       <many-to-one name="topicid" column="topicId" not-null="false"/>      
       <many-to-one name="blogid" column="blogId" not-null="false"/>      
      
        <set name="user_ratings" inverse="true">
           <key column="id" />
           <many-to-many column="id" class="Users"/>
        </set>

        <set name="replies" inverse="true" >
           <key column="id" />
           <one-to-many class="Blogs"/>
        </set>          
                   
    </class>

</hibernate-mapping>


does this look ok to anyone else?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 16, 2005 7:19 pm 
Newbie

Joined: Wed Nov 16, 2005 6:09 pm
Posts: 5
Shouldn't sql-query be after class?

Code:
<hibernate-mapping >
    <class name="com.insaini.publogs.hibernate.tables.Users" table="users">
....
    </class> 

      <sql-query name="user.by.name">
....
      </sql-query>
                 
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 16, 2005 7:33 pm 
Newbie

Joined: Wed Nov 16, 2005 1:55 pm
Posts: 12
Hi, thanks yeah I just saw this now I thought it was inside.. however, i still have another problem :@


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.