NHibernate Exception: Incorrect syntax near the keyword 'user' - nhibernate-mapping

I have a table named as User. I declared my class as
<class name="EETUser" table="User"> it throws "Incorrect syntax near User keyword".
I then changed to <class name="EETUser" table="[User]">
This throws the error as Missing table: [User].
I even tried
<class name="EETUser" table="'User'">
It throws the same exception. Table missing.
Please help me out in this.
NB: I cannot change the table name as this table is an existing one for years.

You need to declare the schema name in your mapping class tag.
Also, remove the quotes around the table name.
If you cannot change the table name, you can create a synonym and map your entity to the synonym name.
<class name="EETUser" table="User" schema="**table.schema.name**">

Related

Weird error: relation <schema name> does not exist

I am running a DDL statement like this in Postgres 11
ALTER SEQUENCE kwt.VisitReport_seq OWNED BY kwt.VisitReport;
I am running it as DBADMIN.
Yet I get some weird error:
SQL Error [42P01]: ERROR: relation "kwt" does not exist
ERROR: relation "kwt" does not exist
ERROR: relation "kwt" does not exist
But this is strange... kwt is not a relation, it is a schema.
What is going on?!
As often happens right after posting here I found the problem.
The statement should be:
ALTER SEQUENCE kwt.VisitReport_seq OWNED BY kwt.VisitReport.ID;
i.e. it should refer (of course) to the column name, not to the table name.

Postgres: Syntax Error whatever I do

I've just installed Postgres. I managed to create a database and use my user name as the name of the database.
I use the command
psql <mydatabase>
However now I'm at this point, I can't do anything.
I tried to type this command for example
CREATE TABLE hosts ( type varchar(20), name varchar(20));
And I always get a syntax error symbol C not exist
What could be the reason for that?

Cannot find data type user defined data type

I am getting Column, parameter, or variable #1: Cannot find data type dbo.SUBSYSTEM_CODE. error on user datatype.
CREATE TABLE #PREDEFINED_SUBSYSTEMS
(
SUBSYSTEM_CODE dbo.SUBSYSTEM_CODE PRIMARY KEY
);
After I checked user defined datatype I can see. I am using SQL 2012 and also I applied set compatibility_level = 110 on datatype still didn't work.
What other alternatives I have to fix this?
Probably you need to define type inside tempdb:
USE tempdb;
GO
CREATE TYPE dbo.SUBSYSTEM_CODE ...
Our problem was with schema
we moved table type from dbo to hub schema, and after that we got this error,
you need to use schema before table name for it to work
and dont forget about dynamic sqls which you might have

creating a view SQL, always getting error

CREATE VIEW CARAVAN AS
SELECT ANNUAL_RENT, BOOKING_FEE
FROM CARAVAN
WHERE ANNUAL_RENT < 3000
this is my failed sql. the error is
ORA-00928: missing SELECT keyword
Try running just the SELECT statement:
SELECT ANNUAL_RENT, BOOKING_FEE
FROM CARAVAN
WHERE ANNUAL_RENT < 3000
And see if that returns a result, or if it generates an error.
My suspicion is that CARAVAN is a view that is INVALID. You can check that with a query from a dictionary view, e.g.
SELECT *
FROM dba_objects
WHERE object_name = 'CARAVAN'
If you don't have privileges on dba_objects, then reference the all_objects instead.
The referenced CARAVAN object is either an object in your schema, a public synonym, or its an invalid reference.
As Alex Poole mentioned, it's possible to create a view that has invalid syntax, by using a CREATE FORCE VIEW statement. (I suspect that the referenced object CARAVAN is a view that contains invalid syntax.)
Identifiers in Oracle have to be unique within a schema. It's very strange that you would be creating a view named CARAVAN that references an object already named CARAVAN. It's not clear what problem you are trying to solve with this particular CREATE VIEW statement.

When to qualify the schema name of an object in Oracle

What determines whether an Oracle object (table, view, etc.) is required to be qualified with a schema name (for example, schema.table_name, or schema.view_name, etc.)? At times I am able to access a remote objects (via a DB link) without having to qualify the schema, but other times, I receive an error stating that the "table or view doesn't exist", and to correct this, I must qualify the schema name.
I am aware that it is a best practice to always qualify a schema name, but I am just curious why I am able to access certain remote objects without a qualified schema, and others only with a qualified schema.
From the Oracle documentation:
http://download.oracle.com/docs/cd/B14117_01/server.101/b10759/sql_elements009.htm
The following example illustrates how Oracle resolves references to objects within SQL statements. Consider this statement that adds a row of data to a table identified by the name departments:
INSERT INTO departments
VALUES
(
280,
'ENTERTAINMENT_CLERK',
206,
1700);
Based on the context of the statement, Oracle determines that departments can be:
A table in your own schema
A view in your own schema
A private synonym for a table or view
A public synonym
Oracle always attempts to resolve an object reference within the namespaces in your own schema before considering namespaces outside your schema. In this example, Oracle attempts to resolve the name departments as follows:
First, Oracle attempts to locate the object in the namespace in your own schema containing tables, views, and private synonyms. If the object is a private synonym, then Oracle locates the object for which the synonym stands. This object could be in your own schema, another schema, or on another database. The object could also be another synonym, in which case Oracle locates the object for which this synonym stands.
If the object is in the namespace, then Oracle attempts to perform the statement on the object. In this example, Oracle attempts to add the row of data to departments. If the object is not of the correct type for the statement, then Oracle returns an error. In this example, departments must be a table, view, or a private synonym resolving to a table or view. If departments is a sequence, then Oracle returns an error.
If the object is not in any namespace searched in thus far, then Oracle searches the namespace containing public synonyms. If the object is in that namespace, then Oracle attempts to perform the statement on it. If the object is not of the correct type for the statement, then Oracle returns an error. In this example, if departments is a public synonym for a sequence, then Oracle returns an error.
What it's saying is that Oracle will check locally for objects you call before expanding its search outwards.
It may well be that there are public (or your own private) synonyms on some of your remote objects allowing you to reference them directly whereas those without the synonyms you'll have to fully qualify.
It depends on what username have you used when you logged in. Or what username was used when the database link was created/configured.
See, for each schema, there is a user. If you logged in as a user "XYZ", then you do not need to qualify object within the "XYZ" schema.