0

I am trying to get a list of all movies from my PostgreSQL db like this:

IQuery query = session.CreateQuery("FROM Movie");

but get this error: ERROR: 42P01: relation "movies" does not exist

Here is a query that I use in pgAdminIII that works

SELECT 
  "Movies"."Id", 
  "Movies"."Title", 
  "Movies"."Director", 
  "Movies"."ReleaseDate"
FROM 
  public."Movies";

It looks like the query is not correct that is being built from nHibernate. Here is the web.config setup.

<configSections>
    <section name="hibernate-configuration" requirePermission="false" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory name="NHibernate.Test">
        <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
        <property name="connection.driver_class">NHibernate.Driver.NpgsqlDriver</property>
        <property name="connection.connection_string">Server=localhost;database=Movies;User ID=movie;Password=password;</property>
        <property name="dialect">NHibernate.Dialect.PostgreSQLDialect</property>
        <property name='proxyfactory.factory_class'>NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
    </session-factory>
</hibernate-configuration>

Any ideas?

1 Answer 1

3

Take a look at the error:

ERROR: 42P01: relation "movies" does not exist

This is lower case movies, not the upper case Movies between double quotes (!) as you use in your piece of SQL. PostgreSQL uses lower case or you have to use double quotes.

Advice: Always use lowercase for objectnames in your database.

Sign up to request clarification or add additional context in comments.

2 Comments

Enclose object names in backticks (``) if you need to keep the mixed case names.
Backtics? That's MySQL-stuff and doesn't work in any other database. Use the ANSI-SQL double quotes if you want, just like the example above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.