Discussion:
Getting value from Oracle sequence
Waqar Sadiq
2011-08-05 23:56:48 UTC
Permalink
Hi,

I am using nHibernate 2.1.2 with Oracle. I have a need to get an
Oracle sequence. I researched on the internet and got eht following
mapping example.

<sql-query name="GetSequence" read-only="true">
<return-scalar column="a" type="Int64"/>
<![CDATA[select SEQ_IDGENERATOR.NextVal from dual]]>
</sql-query>

My C# code that uses it is something like this.

long nextSeq =
Session.GetNamedQuery("GetSequence").UniqueResult<Int64>();

The problem is that when I have a value for the column, I get an
error:

InnerException: System.IndexOutOfRangeException
Message=Unable to find specified column in result set
Source=Oracle.DataAccess

When I do no tprovide any value for column, the I get the following
error:

Message=A valid scalar alias must be specified.
Parameter name: alias
Source=NHibernate

If I leave out column completely, I get the following error:

InnerException: NHibernate.MappingException
Message=(19,6): XML validation error: The required attribute
'column' is missing.
Source=NHibernate

Since in this query, I am not querying a table, I am not sure what is
the significance o fthe column field and what to provide here.

Any help is appreciated.

Thanks,

Waqar
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to nhusers-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to nhusers+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
Okkie
2011-08-08 19:50:50 UTC
Permalink
In your return you define the column named "a". Your query doesnt
produce a column named "a"

try selecting with alias like this:

<sql-query name="GetSequence">
<return-scalar column="value" type="Int64" />
<![CDATA[SELECT SEQ_IDGENERATOR.nextval value FROM DUAL ]]>
</sql-query>

session.GetNamedQuery("GetSequence").UniqueResult<Int64>();
Hi,
I am using nHibernate 2.1.2 with Oracle.  I have a need to get an
Oracle sequence.  I researched on the internet and got eht following
mapping example.
<sql-query name="GetSequence" read-only="true">
    <return-scalar column="a" type="Int64"/>
    <![CDATA[select SEQ_IDGENERATOR.NextVal from dual]]>
  </sql-query>
My C# code that uses it is something like this.
long nextSeq =
Session.GetNamedQuery("GetSequence").UniqueResult<Int64>();
The problem is that when I have a value for the column, I get an
InnerException: System.IndexOutOfRangeException
       Message=Unable to find specified column in result set
       Source=Oracle.DataAccess
When I do no tprovide any value for column, the I get the following
Message=A valid scalar alias must be specified.
Parameter name: alias
Source=NHibernate
InnerException: NHibernate.MappingException
       Message=(19,6): XML validation error: The required attribute
'column' is missing.
       Source=NHibernate
Since in this query, I am not querying a table, I am not sure what is
the significance o fthe column field and what to provide here.
Any help is appreciated.
Thanks,
Waqar
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to nhusers-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to nhusers+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
Okkie
2011-08-08 20:00:11 UTC
Permalink
by the way, if you're using this to generate your primary key you
shouldn't.

mapyour primary key in your hbm like this:

<id name="Id" column="ID" type="Int64" unsaved-value="0">
<generator class="native">
<param name="sequence">SEQ_IDGENERATOR</param>
</generator>
</id>

have fun
Hi,
I am using nHibernate 2.1.2 with Oracle.  I have a need to get an
Oracle sequence.  I researched on the internet and got eht following
mapping example.
<sql-query name="GetSequence" read-only="true">
    <return-scalar column="a" type="Int64"/>
    <![CDATA[select SEQ_IDGENERATOR.NextVal from dual]]>
  </sql-query>
My C# code that uses it is something like this.
long nextSeq =
Session.GetNamedQuery("GetSequence").UniqueResult<Int64>();
The problem is that when I have a value for the column, I get an
InnerException: System.IndexOutOfRangeException
       Message=Unable to find specified column in result set
       Source=Oracle.DataAccess
When I do no tprovide any value for column, the I get the following
Message=A valid scalar alias must be specified.
Parameter name: alias
Source=NHibernate
InnerException: NHibernate.MappingException
       Message=(19,6): XML validation error: The required attribute
'column' is missing.
       Source=NHibernate
Since in this query, I am not querying a table, I am not sure what is
the significance o fthe column field and what to provide here.
Any help is appreciated.
Thanks,
Waqar
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to nhusers-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to nhusers+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
Waqar Sadiq
2011-08-09 04:44:54 UTC
Permalink
After I searched the forum, I found examples of using "NextVal" and
that worked as well. I still don't understand it though. Since there
are no columns in this query, how come nextval or value work?

By the way this is not to generate the primary key but rather to
generate a number for the application to use for various purposes.

Thanks for your help.
Post by Okkie
by the way, if you're using this to generate your primary key you
shouldn't.
<id name="Id" column="ID" type="Int64" unsaved-value="0">
        <generator class="native">
                <param name="sequence">SEQ_IDGENERATOR</param>
        </generator>
</id>
have fun
Hi,
I am using nHibernate 2.1.2 with Oracle.  I have a need to get an
Oracle sequence.  I researched on the internet and got eht following
mapping example.
<sql-query name="GetSequence" read-only="true">
    <return-scalar column="a" type="Int64"/>
    <![CDATA[select SEQ_IDGENERATOR.NextVal from dual]]>
  </sql-query>
My C# code that uses it is something like this.
long nextSeq =
Session.GetNamedQuery("GetSequence").UniqueResult<Int64>();
The problem is that when I have a value for the column, I get an
InnerException: System.IndexOutOfRangeException
       Message=Unable to find specified column in result set
       Source=Oracle.DataAccess
When I do no tprovide any value for column, the I get the following
Message=A valid scalar alias must be specified.
Parameter name: alias
Source=NHibernate
InnerException: NHibernate.MappingException
       Message=(19,6): XML validation error: The required attribute
'column' is missing.
       Source=NHibernate
Since in this query, I am not querying a table, I am not sure what is
the significance o fthe column field and what to provide here.
Any help is appreciated.
Thanks,
Waqar
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to nhusers-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to nhusers+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
Continue reading on narkive:
Loading...