Sequences Mapping and Attributes

137 views
Skip to first unread message

ysta...@hotmail.com

unread,
Apr 6, 2012, 9:45:44 AM4/6/12
to NHibernate Contrib - Development Group
Hi,

I have a problem using NHibernate Attributes. I have an id which
should be generated by a sequence. The sequence already exists in the
database and I just want to get next value of it. I made a query:
IQuery query = session.CreateQuery("select SEQ_QUEST.netxval from
TBL_QUEST_PRODUCT");

but it says that TBL_QUEST_PRODUCT is not mapped [select
SEQ_QUEST.netxval from TBL_QUEST_PRODUCT]

That is my Questionnaire class:
//TBL_QUEST_PRODUCT Table
[XmlRoot("Questionnaire")]
[NHibernate.Mapping.Attributes.Class(Table = "TBL_QUEST_PRODUCT")]
public class Questionnaire
{

public Questionnaire()
{ }


//Database entries
//The QUEST_ID from Database

private int _Quest_Id;

[XmlIgnore()]
[NHibernate.Mapping.Attributes.Id(Column = "QUEST_ID",
TypeType = typeof(int))]
[NHibernate.Mapping.Attributes.Generator(1, Class="sequence")]
public virtual int Quest_Id
{
get { return _Quest_Id; }
set { _Quest_Id = value; }
}

//The PROD_ID from Database
//Connects table TBL_PRODUCT
private int _Prod_Id_Quest;

[XmlIgnore()]
[NHibernate.Mapping.Attributes.Property(0,
Column = "PROD_ID",
TypeType = typeof(int),
NotNull = false)]
public virtual int Prod_Id_Ques
{
get { return _Prod_Id_Quest; }
set { _Prod_Id_Quest = value; }
}

//The QUEST_VER from Database
//From Sequence
private string _Quest_Version;

[NHibernate.Mapping.Attributes.Property(0,
Column = "QUEST_VER",
TypeType = typeof(string),
NotNull = false)]
public virtual string Quest_Version
{
get { return _Quest_Version; }
set { _Quest_Version = value; }
}

//The CREATED_ON Date from Database
private string _Quest_Created_On;

[XmlIgnore()]
[NHibernate.Mapping.Attributes.Property(0,
Column = "CREATED_ON",
TypeType = typeof(string),
NotNull = false)]
public virtual string Quest_Created_On
{
get { return _Quest_Created_On; }
set { _Quest_Created_On = value; }
}

//The CREATED_BY from Table
private string _Quest_Created_By;

[XmlIgnore()]
[NHibernate.Mapping.Attributes.Property(0,
Column = "CREATED_BY",
TypeType = typeof(string),
NotNull = false)]
public virtual string Quest_Created_By
{
get { return _Quest_Created_By; }
set { _Quest_Created_By = value; }
}

//The MODIFIED_ON from Database
private string _Quest_Modified_On;

[XmlIgnore()]
[NHibernate.Mapping.Attributes.Property(0,
Column = "MODIFIED_ON",
TypeType = typeof(string),
NotNull = false)]
public virtual string Quest_Modified_On
{
get { return _Quest_Modified_On; }
set { _Quest_Modified_On = value; }
}

//The MODIFIED_BY Person from Database
private string _Quest_Modified_By;

[XmlIgnore()]
[NHibernate.Mapping.Attributes.Property(0,
Column = "MODIFIED_BY",
TypeType = typeof(string),
NotNull = false)]
public virtual string Quest_Modified_By
{
get { return _Quest_Modified_By; }
set { _Quest_Modified_By = value; }
}

//The CHECKOUT from Database
private string _CheckOut_Quest;

[XmlIgnore()]
[NHibernate.Mapping.Attributes.Property(0,
Column = "CHECKOUT",
TypeType = typeof(string),
NotNull = false)]
public virtual string CheckOut_Quest
{
get { return _CheckOut_Quest; }
set { _CheckOut_Quest = value; }
}
//End of the Database entries


//TBL_QUESTION_GRP entries
private List<QuestionGroup> _QuestionGrp;

[XmlElement("QuestionGroup")]
public virtual List<QuestionGroup> QuestionGrp
{
get { return _QuestionGrp; }
set { _QuestionGrp = value; }
}

I would like to know how to map the table/column to the sequence.
Thank you very much in advance.
Cheers
Yana

Michael Kotten

unread,
Apr 7, 2012, 1:07:44 AM4/7/12
to nhc...@googlegroups.com
This doesn't really belong to the topic, but you have to use CreateSqlQuery, if you want to get the next value of a sequence using plain SQL.
BTW, NHibernate will automatically retrieve the next value of a sequence when saving a new entity, there's no need to do this manually.

Regards

Reply all
Reply to author
Forward
0 new messages