Connect to ESRI Shape File (DBase *.dbf file) from NHibernate - nhibernate

I've been trying to work out how to connect to an ESRI shape file (which I think is a DBase table file) through NHibernate but haven't had any luck with anything I've tried.
Currently, my config's looking like this:
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<!--<property name="dialect">NHibernate.Dialect.GenericDialect</property>
<property name="connection.driver_class">NHibernate.Driver.OdbcDriver</property>
<property name="connection.connection_string">Database=A303.dbf;protocol=TCPIP</property>-->
<property name="connection.driver_class">NHibernate.Driver.OdbcDriver</property>
<!--<property name="connection.connection_string">driver={IBM DB2 ODBC DRIVER};Database=a303.dbf;protocol=TCPIP</property>-->
<property name="connection.connection_string">Provider=VFPOLEDB.1; Data Source=C:\projects\rm4\Sandbox\bin\Debug\A303.dbf;Extended Properties=dBase III</property>
<property name="dialect">NHibernate.Dialect.DB2Dialect</property>
<property name="use_outer_join">true</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
<property name="show_sql">true</property>
I've left the commented out bits in so you can see what values I've been trying. No matter what I try, I get the error message:
ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
I've gone through most of the connection string I've found online and in some answers to questions on here was getting to the 'clutching at straws' phase where I'm just putting anything in so thought I'd better ask for help.
I'm not even sure if it's possible to connect to this type of file from NHibernate but, if it is, does anyone know what should be in the config?

A Shapefile (.shp) is not a dbf, per se. It actually is a collection of files, one of which is a DBF, but the shapefile itself that stores the geometry is a different format altogether.
There is a whitepaper on the ESRI website (www.esri.com)

I would try a different NHibernate driver. Here is a list of NHibernate drivers from the documentation.
Judging from the provider name in your connection string, I would try NHibernate.Driver.OleDbDriver.
Failing this, I would eliminate NHibernate from the mix and see if you can connect using the standard .NET data classes, such as System.Data.Odbc.OdbcConnection and System.Data.OleDb.OleDbConnection. If you cannot connect at this level, then the problem is not NHibernate.

Related

Jackrabbit index boost configuration

I'm trying to understand the use of 'boosting' properties in the indexing configuration for CQ5. I thought I understood from http://wiki.apache.org/jackrabbit/IndexingConfiguration that setting a boost determined how far up the list an item would be returned as a search result. So I tried adding the following boost lines to my default CQ5 indexing configuration:
<index-rule nodeType="nt:base">
<property boost="5.0">jcr:title</property>
<property boost="5.0">history:title</property>
<property boost="3.0">history:description</property>
<property boost="3.0">history:caption</property>
<property boost="2.0">text</property>
<property nodeScopeIndex="false">analyticsProvider</property>
<property nodeScopeIndex="false">analyticsSnippet</property>
<property nodeScopeIndex="false">hideInNav</property>
<property nodeScopeIndex="false">offTime</property>
<property nodeScopeIndex="false">onTime</property>
:
:
<property isRegexp="true">.*:.*</property>
</index-rule>
The intent was that, in a full text search, text found in jcr:title or history:title properties would be the most relevant followed by history:description, history:caption and, finally, text.
I deleted the index information from the repository and from the workspace, then restarted CQ and let it rebuild all of the indexes.
Now when I do a full text search, I'm only getting results if the search text is in the nodename itself - nothing from description, caption, etc.
Obviously I've done something wrong but I'm not sure what. Any help would be greatly appreciated.

Nhibernate connection error

I am using nhibernate 3.1.0, oracle 10g express edition and asp.net 3.5 MVC. I am getting error "ora 06413: connection not open" please help me to solve this problem. My Connection properties are:
<property name="connection.driver_class">NHibernate.Driver.OracleClientDriver</property>
<property name="connection.connection_string">User ID=user;Password=pwd;Data Source=localhost:1521/XE</property>
<property name="show_sql">false</property>
<property name="dialect">NHibernate.Dialect.Oracle10gDialect</property>
<property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
Just taking a stab here - but it looks like your connection string isn't formatted properly.
The connection string you're using appears to be for "XE Client", but I don't think that's what NHibernate uses. I'd be willing to be NHibernate is going to use something more similar to one of the Microsoft connection strings shown on that page.
In all the oracle connection strings I see at ConnectionStrings.com/Oracle it seems the properties "User ID", "Password", and "Data Source" are not valid.
You could also reference this example of using NHibernate with an Oracle server: http://tiredblogger.wordpress.com/2008/11/07/using-oracle-odp-with-nhibernate-from-a-c-class-library/
Apparently Oracle 10g is a bit finicky on 64-bit systems. The best option seemed to be switching to MySQL.
the usage of MySQL also provide more features in hibernate

Entity Data Model - Adding a keyless table

Visual studio is giving me a trail of errors that I have hit a dead end on. I am trying to add an existing table in a database to my data model. I understand that the table should have a key, but it doesn't and I can't fix that; it isn't my database to re-design.
When I first try to add the table, I get this error:
The table/view
'BT8_GC.dbo.SAVED_QUERY_CATEGORY' does
not have a primary key defined and no
valid primary key could be inferred.
This table/view has been excluded. To
use the entity, you will need to
review your schema, add the correct
keys, and uncomment it.
Ok, fine, I'll define the keys for it and uncomment. Here is the block I uncomment, after manually defining the keys (I also had to add the nullable=false part):
<EntityType Name="SAVED_QUERY_CATEGORY">
<Key>
<PropertyRef Name="SQC_CAT_ID"/>
<PropertyRef Name="SQC_USER_ID"/>
</Key>
<Property Name="SQC_CAT_ID" Type="int" Nullable="false" />
<Property Name="SQC_USER_ID" Type="int" Nullable="false" />
<Property Name="SQC_CAT_DSCR" Type="varchar" MaxLength="50" />
<Property Name="SQC_SEQ_NO" Type="int" />
</EntityType>
Nope, now the designer won't open. Go back into the file, and Intellisense shows this error:
Error 11002: Entity Type 'SAVED_QUERY_CATEGORY' has no entity set.
Ok... Uncommenting created a new error. After adding an entity set:
<EntitySet Name="SAVED_QUERY_CATEGORY" EntityType="IssueModel.Store.SAVED_QUERY_CATEGORY" store:Type="Tables" Schema="dbo" />
Yay! The designer opens! Still not there yet, because while it shows up under the store's Tables/Views folder, it has not Entity Type in the model. Can't call it from my code. I don't have any errors to work off though, so I tried creating an entity set mapping, but that results in the error "does not exist in MetadataWorkspace".
So that's what I have tried. How do I get this poorly designed table into my data model?
By modifying XML you have only added information about database table. Now you have to open toolbox and add entity to your model in the designer. Configure the entity to have properties as you need. Then open mapping details and map the new entity to your table.
Btw. once you modify the XML describing database manually you cannot use update from database anymore - VS designer will always delete your changes and you will have to do them again.

Unable to bulk insert using NHibernate

I've tried adding bulk inserting to my application, but the Batcher is still NonBatchingBatcher with a BatchSize of 1.
This is using C#3, NH3RC1 and MySql 5.1
I've added this to my SessionFactory
<property name="adonet.batch_size">100</property>
And my code goes pretty much like this
var session = SessionManager.GetStatelessSession(type);
var tx = session.BeginTransaction();
session.Insert(instance);
I'm using HILO identity generation for the instances in question, but not for all instances on the database. The SessionFactory.OpenStatelessSession doesn't take a type, so it can't really know it can do batching on this type, or...?
After some digging into NHibernate, I found something in SettingsFactory.CreateBatcherFactory that might give some additional info
// It defaults to the NonBatchingBatcher
System.Type tBatcher = typeof (NonBatchingBatcherFactory);
// Environment.BatchStrategy == "adonet.factory_class", but I haven't
// defined this in my config file
string batcherClass = PropertiesHelper.GetString(Environment.BatchStrategy, properties, null);
if (string.IsNullOrEmpty(batcherClass))
{
if (batchSize > 0)
{
// MySqlDriver doesn't implement IEmbeddedBatcherFactoryProvider,
// so it still uses NonBatchingFactory
IEmbeddedBatcherFactoryProvider ebfp = connectionProvider.Driver as IEmbeddedBatcherFactoryProvider;
Could my configuration be wrong?
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
<session-factory name="my application name">
<property name="adonet.batch_size">100</property>
<property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
<property name="connection.connection_string">my connection string
</property>
<property name="dialect">NHibernate.Dialect.MySQL5Dialect</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
<!-- To avoid "The column 'Reserved Word' does not belong to the table : ReservedWords" -->
<property name="hbm2ddl.keywords">none</property>
</session-factory>
</hibernate-configuration>
I know this question is a year old, but there is a NuGet package that adds MySQL batching functionality to NHibernate. The reason that it's not baked directly into NHibernate is that the functionality required a reference to the MySQL.Data assembly, and the dev team didn't want the dependency.
IIRC, batching is currently supported for Oracle and SqlServer only.
As almost any other aspect of NH, this is extensible, so you can write your own IBatcher/IBatcherFactory and inject them via configuration.
Sidenote: current version of NH is 3.0 GA.
Really old question but...let's be completely correct
Another reason for batching not working can be use of stateless session (as in your case). Stateless session does not support batching. From documentation:
The insert(), update() and delete() operations defined by the
StatelessSession interface are considered to be direct database
row-level operations, which result in immediate execution of a SQL
INSERT, UPDATE or DELETE respectively. Thus, they have very different
semantics to the Save(), SaveOrUpdate() and Delete() operations
defined by the ISession interface.

NHibernate - Trying to get it to use a SQL Server Row version

As per the StackOverflow question 'NHibernate and sql timestamp columns as version', I use the following mapping:
<version name="RowNumber" generated="always" unsaved-value="null" type="BinaryBlob">
<column name="RowNumber" not-null="false" sql-type="timestamp" />
</version>
<property name="CreateDate" column="CreateDate" type="DateTime" update="false" insert="false" />
(Other properties after this last).
But when I run my ASP.MVC app I get:
[Path]\Clients.hbm.xml(7,90): XML validation error: The element 'urn:nhibernate-mapping-2.2:version' cannot contain child element 'urn:nhibernate-mapping-2.2:column' because the parent element's content model is empty.
But as far as I can see 2.2 is the latest version of the mapping, so how can anyone put a column element inside the version element?
Sorry if this is really basic,
In case anyone else has this problem:
It works as Ayende Rahien specifies in this blog on NHibernate - but only (AFAIK) on version 2.1.n; I was using 2.0.n. I also think you need the object's field/property to be byte[], not System.Linq.Binary as that type has no default constructor (but I am not sure about this - I seemed to have to do this)
Example (excuse the names):
<version name="RowKludge" type="BinaryBlob" generated="always" unsaved-value="null" >
<column name="RowNumber"
not-null="false"
sql-type="timestamp"/>
</version>
A SQL server 'timestamp' is not your regular timestamp, hence the requirement that the type should be a binary blob.
Note that if you do migrate you will need to change the NHibernate configuration in Web/App config - most tutorials currently available seem to be for v.2.0 (or earlier) - you need an uptodate reference or tutorial for 2.1
A quick look in the documentation reveals that your mapping is not correct. It should be something like this:
<version name="RowNumber" column="RowNumber"
generated="always" unsaved-value="null"
type="Timestamp" />
Best Regards,
Oliver Hanappi