I am trying to combine these 3 sql statements to output into one XML statement that outputs like this example:
<dataset seriesName="Model A12" color="A66EDD" >
<set value="35" />
<set value="42" />
<set value="31" />
<set value="28" />
<set value="34" />
<set value="30" />
</dataset>
<dataset seriesName="Model A15" color="F6BD0F">
<set value="22" />
<set value="25" />
<set value="18" />
<set value="22" />
<set value="17" />
<set value="16" />
</dataset>
Here are my SQL Statements:
(SELECT CLAIM_NUM as 'CATEGORY_LABEL' from claim_table)
for xml RAW, TYPE,ROOT('CATEGORY');
(SELECT TOTAL_INCURRED_AMT as 'SET_VALUE' from claim_table)
for xml RAW, TYPE, ROOT('DATASET');
SELECT TOTAL_PAID_AMT as 'SET_VALUE' from claim_table
for xml RAW, TYPE, ROOT('DATASET');
I have been looking at other examples, but nothing has come close to what I need the output to be.
Thanks is advance for your assistance!
Related
I need to move out of mule and jetty/jersey in my web service. I'm looking for a alternative way to implement the current code.
I'm starting the service like this -
org.mule.MuleServer -config deploy_jetty_jersey.xml
deploy_jetty_jersey.xml
http://www.mulesource.org/schema/mule/jetty/2.2
http://www.mulesource.org/schema/mule/jetty/2.2/mule-jetty.xsd
http://www.mulesource.org/schema/mule/core/2.2
http://www.mulesource.org/schema/mule/core/2.2/mule.xsd
http://www.mulesource.org/schema/mule/jersey/2.2
http://www.mulesource.org/schema/mule/jersey/2.2/mule-jersey.xsd
http://www.mulesource.org/schema/mule/vm/2.2
http://www.mulesource.org/schema/mule/vm/2.2/mule-vm.xsd">
<jetty:connector name="httpConnector" useContinuations="true"
configFile="jettyConfig.xml" />
<jetty:endpoint address="http://localhost:8080" name="serverEndpoint"
path="html" synchronous="false" />
<model name="ServiceSample">
<service name="testComponent">
<inbound>
<jetty:inbound-endpoint ref="serverEndpoint" />
</inbound>
</service>
<service name="restTestHello" initialState="started">
<inbound>
<inbound-endpoint address="jersey:http://localhost:7003/rest"
synchronous="true" />
</inbound>
<component>
<singleton-object class="com.rest.RestResource" />
</component>
</service>
</model>
jettyConfig.xml
<Set name="handler">
<New id="Handlers" class="org.mortbay.jetty.handler.HandlerCollection">
<Set name="handlers">
<Array type="org.mortbay.jetty.Handler">
<Item>
<New id="Contexts" class="org.mortbay.jetty.handler.ContextHandlerCollection" />
</Item>
<Item>
<New id="DefaultHandler" class="org.mortbay.jetty.handler.DefaultHandler" />
</Item>
<Item>
<New id="StaticHandler" class="org.mortbay.jetty.handler.ResourceHandler" />
</Item>
<Item>
<New class="org.mortbay.jetty.handler.ContextHandler">
<Set name="contextPath">/</Set>
<Set name="resourceBase">
<SystemProperty name="jetty.home" default="." />
XXXXXX
</Set>
<Call name="addHandler">
<Arg>
<New class="org.mortbay.jetty.handler.ResourceHandler" />
</Arg>
</Call>
</New>
</Item>
</Array>
</Set>
</New>
</Set>
<Call name="addLifeCycle">
<Arg>
<New class="org.mortbay.jetty.deployer.WebAppDeployer">
<Set name="contexts">
<Ref id="Contexts" />
</Set>
<Set name="webAppDir">XXX</Set>
</New>
</Arg>
</Call>
<Set name="stopAtShutdown">true</Set>
<Set name="sendServerVersion">true</Set>
<Set name="sendDateHeader">true</Set>
<Set name="gracefulShutdown">1000</Set>
I need an alternate software which uses similar xml structure, so that there will be minimal java change.
The obvious alternative would be to move to a newer Mule version and replace the jetty connector with an HTTP Listener. If you define your REST API with a RAML file you can also use APIKit routing and validation.
I'm using a mapping with a filter.
But when I try to persist my object, it first wants to get a snapshot (because my Id is a string).
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="DomainLayer.General" assembly="DomainLayer">
<class name="Fund" table="OPENA_BriefW" lazy="false">
<id name="Id" column="`BRWNUMMER`" type="string" >
</id>
<property name="Name" column="`BRWNAAM`" type="string" />
<property name="Contact" column="`BRWNAAM2`" type="string" />
<property name="Address" column="`BRWADRES`" type="string" />
<property name="City" column="`BRWSTAD`" type="string" />
<property name="Zip" column="`BRWPOST`" type="string" />
<property name="Phone" column="`BRWTELEFOON`" type="string" />
<property name="Fax" column="`BRWTELEFAX`" type="string" />
<property name="Iban" column="`brw_iban`" type="string" />
<property name="BankAccount" column="`BRWBANKNU`" type="string" />
<property name="Swift" column="`brw_swift`" type="string" />
<property name="ReceiveOffice" column="`BRWONTVKANT`" type="int" />
<property name="RegionDirection" column="`BRWGEWESTDIR`" type="int" />
<many-to-one name="Country" class="DomainLayer.General.CodeDescription" fetch="join" not-found="ignore">
<formula>'ALG'</formula>
<formula>'0'</formula>
<formula>'WG030'</formula>
<column name="`BRWLAND`" />
<formula>:LanguageFilter.Id</formula>
</many-to-one>
</class>
</hibernate-mapping>
As you can see the filter :LanguageFilter.Id is the one causing the troubles. When I do a normal .List() it doesn't cause problems.
But when I persist, it first wants to check if the Fund already exists yes/no. By doing a .Get (with the Id).
Then I get the error can't retrieve snapshot because in my query he doesn't replace :LangaugeFilter.Id with the effective value i set on my session.
I enable the filter on my session like so:
session.EnableFilter("LanguageFilter").SetParameter("Id", 1);
Here's the filter-def mapping:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<filter-def name='LanguageFilter' >
<filter-param name='Id' type='System.Int32' />
</filter-def>
</hibernate-mapping>
This post (comment 4) http://ayende.com/blog/3993/nhibernate-filters says that session.Get and Load ignores filters.
Are there any alternatives, because I need that language to be variable.
Ok, what I did was the following: I didn't use SaveOrPersist, but Save when new and Persist when I had an old one. This didn't execute the extra get.
I have a named query in my nhibernate mapping file, and every time i run the code, it fails to create the Session with the message 'Errors in named queries', and no inner exception or anything else pointing to what's wrong with my named query. I'm very new to using nhibernate but am sure i have everything set up correctly (i.e. mapping file is an embedded resource, and the classes used in the query are mapped correctly).
Could anyone suggest if there is an obvious error or problem with my mapping file which may cause this error.
Mapping file:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
schema="SmokefreeServices.Common"
assembly="Model.Smoking"
namespace="Model.Smoking">
<class name="CommonReferral" table="Referral">
<id name="ID">
<generator class="identity" />
</id>
<property name="PatientID" />
<property name="Module" />
<property name="OriginalModule" />
<property name="ReferralSource" />
<property name="OtherReferralSource" />
<property name="ReferralDate" />
<property name="ReferralComments" />
<property name="CreatedBy" />
<property name="CreatedDate" />
<property name="UpdatedBy" />
<property name="UpdatedDate" />
<one-to-one name="Status" class="CurrentReferralStatus" fetch="join" />
<bag name="StatusHistory" inverse="true" lazy="true">
<key column="ReferralID" />
<one-to-many class="ReferralStatus" />
</bag>
</class>
<query name="GetOpenReferral">
<![CDATA[
from CommonReferral ref
inner join fetch ref.Status referralStatus
where ref.PatientID = :patientId
and referralStatus.IsResolved = 0
]]>
</query>
</hibernate-mapping>
Is it a mapping problem between CommonReferal and CurrentReferralSttaus. Out of interest what happens if you try this:-
<query name="GetOpenReferral">
<![CDATA[
from CommonReferral ref
where ref.PatientID = :patientId
]]>
</query>
Another quick thought can you try and remove the keyword fetch as one-to-one are always eager fetched anyway.
<query name="GetOpenReferral">
<![CDATA[
from CommonReferral ref
inner join ref.Status referralStatus
where ref.PatientID = :patientId
and referralStatus.IsResolved = 0
]]>
</query>
I am trying to switch a table from being a many-to-one mapping to being many-to-many with an intermediate mapping table. However, when I switched it over and tried to do a query on it with NHibernate, it's giving me this error: "Interceptor.OnPrepareStatement(SqlString) returned null or empty SqlString."
My query was originally something more complex, but I switched it to a basic fetch all and I'm still having the problem:
Session.QueryOver<T>().Future();
It would seem to either be a problem in my model mapping files or something in my database.
Here are my model mappings:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="GBI.Core" namespace="GBI.Core.Models">
<class name="Market" table="gbi_Market">
<id name="Id" column="MarketId">
<generator class="identity" />
</id>
<property name="Name" />
<property name="Url" />
<property name="Description" type="StringClob" />
<property name="Rating" />
<property name="RatingComment" />
<property name="RatingCommentedOn" />
<many-to-one name="RatingCommentedBy" column="RatingCommentedBy" lazy="proxy"></many-to-one>
<property name="ImageFilename" />
<property name="CreatedOn" />
<property name="ModifiedOn" />
<property name="IsDeleted" />
<many-to-one name="CreatedBy" column="CreatedBy" lazy="proxy"></many-to-one>
<many-to-one name="ModifiedBy" column="ModifiedBy" lazy="proxy"></many-to-one>
<set name="Content" where="IsDeleted=0 and ParentContentId is NULL" order-by="Ordering asc, CreatedOn asc, Name asc" lazy="extra">
<key column="MarketId" />
<one-to-many class="MarketContent" />
</set>
<set name="FastFacts" where="IsDeleted=0" order-by="Ordering asc, CreatedOn asc, Name asc" lazy="extra">
<key column="MarketId" />
<one-to-many class="MarketFastFact" />
</set>
<set name="NewsItems" table="gbi_NewsItem_Market_Map" lazy="true">
<key column="MarketId" />
<many-to-many class="NewsItem" fetch="join" column="NewsItemId" where="IsDeleted=0"/>
</set>
<!--<set name="MarketUpdates" table="gbi_Market_MarketUpdate_Map" lazy="extra">
<key column="MarketId" />
<many-to-many class="MarketUpdate" fetch="join" column="MarketUpdateId" where="IsDeleted=0" order-by="CreatedOn desc" />
</set>-->
<set name="Documents" table="gbi_Market_Document_Map" lazy="true">
<key column="MarketId" />
<many-to-many class="Document" fetch="join" column="DocumentId" where="IsDeleted=0"/>
</set>
</class>
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="GBI.Core" namespace="GBI.Core.Models">
<class name="MarketUpdate" table="gbi_MarketUpdate">
<id name="Id" column="MarketUpdateId">
<generator class="identity" />
</id>
<property name="Description" />
<property name="CreatedOn" />
<property name="ModifiedOn" />
<property name="IsDeleted" />
<!--<many-to-one name="Market" column="MarketId" lazy="proxy"></many-to-one>-->
<set name="Comments" where="IsDeleted=0" order-by="CreatedOn desc" lazy="extra">
<key column="MarketUpdateId" />
<one-to-many class="MarketUpdateComment" />
</set>
<many-to-one name="CreatedBy" column="CreatedBy" lazy="proxy"></many-to-one>
<many-to-one name="ModifiedBy" column="ModifiedBy" lazy="proxy"></many-to-one>
</class>
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="GBI.Core" namespace="GBI.Core.Models">
<class name="MarketUpdateMarketMap" table="gbi_Market_MarketUpdate_Map">
<id name="Id" column="MarketUpdateMarketMapId">
<generator class="identity" />
</id>
<property name="CreatedOn" />
<property name="ModifiedOn" />
<property name="IsDeleted" />
<many-to-one name="CreatedBy" column="CreatedBy" lazy="proxy"></many-to-one>
<many-to-one name="ModifiedBy" column="ModifiedBy" lazy="proxy"></many-to-one>
<many-to-one name="MarketUpdate" column="MarketUpdateId" lazy="proxy"></many-to-one>
<many-to-one name="Market" column="MarketId" lazy="proxy"></many-to-one>
</class>
As I mentioned, MarketUpdate was originally a many-to-one with Market (MarketId column is still in there, but I'm ignoring it. Could this be a problem?). But I've added in the Market_MarketUpdate_Map table to make it a many-to-many.
I'm running in circles trying to figure out what this could be. I couldn't find any reference to this error when searching. And it doesn't provide much detail.
Using:
NHibernate 2.2
.NET 4.0
SQL Server 2005
Turns out the problem was just that the xml mapping file was set as content instead of embedded resource in visual studio. Changing that fixed all my problems.
If you're using Fluent rather than xml for mappings and encounter this issue, try deleting the generated xml files in %root%\LocalCache\NHibernate.
I'm trying to pull back a list of items that have a specific type of item in a set.
For example:
<class name="Owner" table="OWNER">
<id name="id" column="OWNER_ID" />
<set name="cats" table="OWNER_CATS" lazy="false">
<key column="OWNER_ID" />
<many-to-many class="Cat" />
</set>
<class name="Cat" table="CAT" discriminator-value="C">
<id name="id" column="CAT_ID" />
<discriminator column="type" type="character" />
<subclass name="Lion" discriminator-value="L">
<property name="teeth" />
</subclass>
</class>
Using restrictions how would I get a list of owners who have lions as pets?
I've tried something along the lines of the following to no avail:
criteria.createCriteria("cats").add(Restrictions.eq("class", Lion.class));
At the moment (though I'm not sure if this is intentional) the way this works is you have to specify the discriminator value as the restriction value, rather than the class itself, so:
criteria.createCriteria("cats").add(Restrictions.eq("class", "L"));
in your example.