Should NHibernate generate SQL for GUID parameter without quotes? - sql-server

Sql Server 2008 R2 Express. NHibernate 2.1.2.4.
I get SQL like:
SELECT customer0_.Id as Id1_0_
FROM customers customer0_
WHERE customer0_.Id=#p0;
#p0 = 11111111-1111-1111-1111-111111111111
...which returns 0 records even though there is Customer in there with that Id.
The SQL Server column datatype is UNIQUEIDENTIFIER.
<session-factory> configured as follows:
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
Class's <id> configured as follows
<id name="_id" column="Id" type="Guid" access="field" unsaved-value="00000000-0000-0000-0000-000000000000" >
<generator class="guid.comb" />
</id>
Forging my way through this for the first time, w/ the help of various tuts. I've been over everything several times but no joy. Any ideas what is wrong/missing here? TYIA!

This seems correct. According to this "we must remember that a Guid is not a string even thought that's how we see them. A Guid is a 16-byte data structure." So I'm not sure why you are not getting back the results you expect, but I think the generated SQL is correct in not having the quotes.

Related

Dynamic TableName SOLR data import handler

I'm looking to configure SOLR to query a table based on certain data.
I unfortunately have to work with how the Database is setup, but here's what I'm after.
I have a table named Company that will contain a certain "prefix" value.
I want to use that prefix value to determine what tables I should query for the DIH.
As a quick sample:
<entity name="company" query="Select top 1 prefix from Company">
<field name="prefix" column="prefix"/>
<entity name="item" query="select * from ${company.prefix}item">
<field column="ItemID" name="id"/>
<field column="Description" name="description/>
</entity>
</entity>
However I only ever seem to get 1 document processed despite that table containing over 200,000 rows.
what am I doing wrong?
I think you could achieve this by:
using an stored procedure. You can call a sp from DIH as seen here
inside the stored procedure, you can do the table lookup as needed, and then return the results from the real query.
Depending on how good you are with MSSql-s SQL, you might be able to just put everything into a single SQL query and use that directly in DIH, but not sure about that.

Why doesn't Google Cloud DataStore support multiple inequality filter on different properties?

I know that is a limitation of DataStore, But I just want to figure out the reason.
Invalid Argument: Cannot have inequality filters on multiple properties: [..., ...]
I have read the bigtable paper and I can not find any restriction on inequality filter on different column. and it can support prefix and range scan. IMHO, DataStore could support that multiple inequality filter with these two operation. Do you know any reason take the functionality from DataStore?
To avoid having to scan the entire index table, the query mechanism relies on
all of a query's potential results being adjacent to one another in the index.
To satisfy this constraint, a single query may not use inequality comparisons
(LESS_THAN, LESS_THAN_OR_EQUAL, GREATER_THAN, GREATER_THAN_OR_EQUAL, NOT_EQUAL)
on more than one property across all of its filters
[Source : https://cloud.google.com/appengine/docs/standard/java/datastore/query-restrictions ]
Every datastore query is running on one or more index table.
When considering inequality filters, we want to run on at most one property in order to avoid running on the entire index tables. It's easier to grasp when investigating how Filters work, how datastore-indexes.xml defined and what is index exactly:
<datastore-index> are elements, one for every index that the Datastore should maintain. So, you defining one index (which is a table) for every relation between Entity's kind and it's properties. Now imagine when you need to calculate multiple inequality filter on different properties? It can lead to a huge running time. Not good.
<?xml version="1.0" encoding="utf-8"?>
<datastore-indexes autoGenerate="true">
<datastore-index kind="Greeting" ancestor="true" source="manual">
<property name="user" direction="asc" />
<property name="birthYear" direction="asc" />
<property name="height" direction="asc" />
</datastore-index>
<datastore-index kind="Greeting" ancestor="true" source="manual">
<property name="date" direction="asc" />
</datastore-index>
</datastore-indexes>
Now, let's see filters.
It's a valid filter - he runs on one property only (the birthYear property).
Filter birthYearMinFilter =
new FilterPredicate("birthYear",
FilterOperator.GREATER_THAN_OR_EQUAL,
minBirthYear);
Filter birthYearMaxFilter =
new FilterPredicate("birthYear",
FilterOperator.LESS_THAN_OR_EQUAL,
maxBirthYear);
Filter birthYearRangeFilter =
CompositeFilterOperator.and(birthYearMinFilter, birthYearMaxFilter);
Query q = new Query("Person").setFilter(birthYearRangeFilter);
It's a non-valid filter, he runs on 2 properties (birthYear and height):
Filter birthYearMinFilter =
new FilterPredicate("birthYear",
FilterOperator.GREATER_THAN_OR_EQUAL,
minBirthYear);
Filter heightMaxFilter =
new FilterPredicate("height",
FilterOperator.LESS_THAN_OR_EQUAL,
maxHeight);
Filter invalidFilter =
CompositeFilterOperator.and(birthYearMinFilter, heightMaxFilter);
Query q = new Query("Person").setFilter(invalidFilter);

AdventureWorks can't create ado.net entity data model

I'm trying to use microsoft's sample database AdventureWorks2008R2... when I try to create the ADO.NET entity data model I get this error:
Unable to generate the model because of the following exception: 'The table 'C:\USERS\XXXX\DOCUMENTS\VISUAL STUDIO 2010\PROJECTS\ANOTHERWORKS\ANOTHERWORKS\APP_DATA\ADVENTUREWORKS2008R2_DATA.MDF.Production.Document' was referenced by a relationship, but was not found.'.
Loading metadata from the database took 00:00:06.2308687.
Generating the model took 00:00:04.5808698.
Added the connection string to the Web.Config file.
Successfully registered the assembly 'System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' in the Web.Config file.
Writing the .edmx file took 00:00:00.0015898.
Anyone encountered and fixed this? Or knows somewhere I can download a working version of this database ( other then: http://msftdbprodsamples.codeplex.com/releases/view/59211 which is where I got it )
Or can someone point to a sample database I can download and use around with entity framework.
EDIT
The new EF designer (Beta 1 available here) will not try creating relationships to non-existing tables so instead of the error and empty model you will get a model where invalid entity types/sets and relationships are commented out.
**
I looked at it for AdventureWorks for Sql Server 2012 but I think it is the same thing you hit for 2008R2/
The issue here is that the Production.Document table has a key that is of HierarchyId type and EF currently does not support HierarchyId type. EF ignores columns of types it does not understand when creating the model however if it does not understand a key column it will exclude the entire entity from the model. For excluded entities you should be able to find them commented out in the model when you open it with an Xml/Text editor. In this particular case this is what will see:
<EntityContainer Name="AdventureWorksModelStoreContainer" />
<!--Errors Found During Generation:
warning 6005: The data type 'hierarchyid' is currently not supported for the target .NET Framework version; the column 'DocumentNode' in table 'AdventureWorks.Production.Document' was excluded.
warning 6031: The column 'DocumentNode' on the table/view 'AdventureWorks.Production.Document' was excluded, and is a key column. The table/view has been excluded. Please fix the entity in the schema file, and uncomment.
<EntityType Name="Document">
<Property Name="DocumentLevel" Type="smallint" StoreGeneratedPattern="Computed" />
<Property Name="Title" Type="nvarchar" Nullable="false" MaxLength="50" />
<Property Name="Owner" Type="int" Nullable="false" />
<Property Name="FolderFlag" Type="bit" Nullable="false" />
<Property Name="FileName" Type="nvarchar" Nullable="false" MaxLength="400" />
<Property Name="FileExtension" Type="nvarchar" Nullable="false" MaxLength="8" />
<Property Name="Revision" Type="nchar" Nullable="false" MaxLength="5" />
<Property Name="ChangeNumber" Type="int" Nullable="false" />
<Property Name="Status" Type="tinyint" Nullable="false" />
<Property Name="DocumentSummary" Type="nvarchar(max)" />
<Property Name="Document" Type="varbinary(max)" />
<Property Name="rowguid" Type="uniqueidentifier" Nullable="false" />
<Property Name="ModifiedDate" Type="datetime" Nullable="false" />
</EntityType>-->
</Schema>
Notice this warning:
warning 6031: The column 'DocumentNode' on the table/view 'AdventureWorks.Production.Document' was excluded, and is a key column. The table/view has been excluded. Please fix the entity in the schema file, and uncomment.
Now in the AdventureWorks database the Production.Document table is referenced by Production.ProductDocument table. Since no entity for Production.Document table was created EF is unable to create the reference from Production.ProductDocument entity and hence the "Production.Document' is referenced by a relationship, but cannot be found.' error.
Since the Production.Document table cannot be really used "as is" by EF the easiest workaround is to exclude this entity when generating the model from entity - check all tables but Production.Document in the wizard and you should be good to go. EF will ignore all references to this entity since you excluded it and therefore there should be no error.
Link to a related work item on Entity Framework codeplex site

How to work with liquibase, a concrete example

Following the quickstart on liquibase i've created a changeset (very dumb :) )
Code:
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog/1.6"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog/1.6
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.6.xsd">
<changeSet id="1" author="me">
<createTable tableName="first_table">
<column name="id" type="int">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="name" type="varchar(50)">
<constraints nullable="false"/>
</column>
</createTable>
<createTable tableName="new_table">
<column name="id" type="int">
<constraints primaryKey="true" nullable="false"/>
</column>
</createTable>
</changeSet>
</databaseChangeLog>
I've created a clean schema and i've launched the migrate command.
Liquibase created the database, with the support tables databasechangelog and ..lock.
Now how i can track the changes?? i've modified the changeset adding a new createTable element but when i try the command "update" liquibase tells me this
Migration Failed: Validation Failed:
1 change sets check sum
so i don't think to have understood the way to work with liquibase.
Someone may point me to the right direction??
Thanks
You should never modify a <changeSet> that was already executed. Liquibase calculates checksums for all executed changeSets and stores them in the log. It will then recalculate that checksum, compare it to the stored ones and fail the next time you run it if the checksums differ.
What you need to do instead is to add another <changeSet> and put your new createTable element in it.
QuickStart is good readin' but it is indeed quick :-) Check out the full manual, particularly its ChangeSet section.
This currently accepted answer is slightly out of date based on changes in Liquibase 2.x. In the 2.x version, Liquibase will still fail if the md5 checksum has changed for a changeset, but you can specify the runOnChange attribute if you want to be able modify it.
From the documentation:
runOnChange - Executes the change the first time it is seen and each time the change set has been changed
If it's a change to a changeset that basically has already been done, you can manually modify the database so that its md5 for that changeset matches the new one. Good for minor textual changes. Or you can delete that changeset row from your table.

Why is SSRS ignoring data from certain columns returned by a web method?

I'm using the XML data source feature in Reporting Services 2005 but having some issues with missing data. When there is no value for the first column in a row, it appears that the entire column is ignored by SSRS!
The web method request is very simple:
<Query>
<Method Name="GetIssues"
Namespace="http://www.mycompany.com/App/">
</Method>
<SoapAction>http://www.mycompany.com/App/GetIssues</SoapAction>
<ElementPath IgnoreNamespaces="true">*</ElementPath>
</Query>
Equally, the response is very simple:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetIssuesResponse xmlns="http://www.mycompany.com/App/">
<GetIssuesResult>
<Issue>
<Title>ABC</Title>
<RaisedBy />
<Action>Do something</Action>
</Issue>
<Issue>
<Title>ABC</Title>
<RaisedBy>Jeff Smith</RaisedBy>
<Action>Do something</Action>
</Issue>
</GetIssuesResult>
</GetIssuesResponse>
</soap:Body>
</soap:Envelope>
In this example the RaisedBy column will be completely empty. If the 'Issues' are reversed so RaisedBy first has a value, there is no problem. Any ideas?
In the Query itself, try to define your columns explicitly, instead of letting SSRS determine them for you.
In other words, where you have:
<ElementPath IgnoreNamespaces="true">*</ElementPath>
Replace the * with something like:
<ElementPath IgnoreNamespaces="true">GetIssues/GetIssuesItemsResult/listitems/data/row{#Title,#RaisedBy,#Action}</ElementPath>
Of course, that exact XPath may not be correct for your example.
Is it possible to eliminate the NULLs in the XML? Replace them with an empty string? Then you won't have to wrestle with SSRS.
If the XML is generated from a database call, that's easy enough to do (ISNULL in SQL Server).

Resources