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.  [ 2 posts ] 
Author Message
 Post subject: Properties mapped with native SQL?
PostPosted: Fri Apr 10, 2009 12:47 pm 
Newbie

Joined: Thu Mar 12, 2009 5:31 pm
Posts: 16
I have this native sql statement that I need mapped to a property.

I want a property that I need to contain a List<Device> populated by a native sql statement. I noticed that the property attribute allows custom sql formulas. Unfortunately, nHibernate is wrapping my stored procedure in a select GROUP query, not even a select device query. Take a look at my code below:

Below is my mapping file for
Group.hbm.xml:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   assembly="DataServices.BusinessEntities"
                   namespace="DataServices.BusinessEntities">
  <class name="Group" table="Groups">
    <id name="Id" type="Int32" column="Id" access="property">
      <generator class="identity">
        <param name="table">Extensions</param>
        <param name="column">Id</param>
      </generator>
    </id>
    <property name="Name" column="Name"/>
    <property name="Description" column="Description"/>
    <property name="AllDevices" type="DataServices.BusinessEntities.Device, DataServices.BusinessEntities" formula="(dbo.GetAllDevicesInGroup(id))">
    </property>
  </class>
</hibernate-mapping>


Device.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   assembly="DataServices.BusinessEntities"
                   namespace="DataServices.BusinessEntities">
  <class name="Device" table="Devices">
    <id name="Id" type="Int32" column="Id" access="property">
      <generator class="identity">
        <param name="table">Devices</param>
        <param name="column">Id</param>
      </generator>
    </id>
    <property name ="Name" column="Name"/>
    <property name ="Description" column="Description"/>
  </class> 
</hibernate-mapping>


When I try to get a group from the database, I get this:
could not execute query
Code:
[ SELECT this_.Id as Id7_0_, this_.Name as Name7_0_, this_.Description as Descript3_7_0_, (dbo.GetAllDevicesInGroup(this_.id)) as formula0_0_ FROM Groups this_ WHERE this_.Id = ? ]
Positional parameters:  #0>2614
[SQL: SELECT this_.Id as Id7_0_, this_.Name as Name7_0_, this_.Description as Descript3_7_0_, (dbo.GetAllDevicesInGroup(this_.id)) as formula0_0_ FROM Groups this_ WHERE this_.Id = ?]


Its wrapping my stored procedure as a GROUP, when I need a DEVICE


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 11, 2009 5:18 am 
Regular
Regular

Joined: Wed Feb 11, 2009 10:58 am
Posts: 55
It sounds like there are more devices in a Group? How can I map more devices into a property?

maybe a Set or List with a custom query will do the trick?


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