Joined: Wed Dec 12, 2007 12:41 am Posts: 4 Location: Minsk, Belarus
|
Small intro: I just started to work in small software sales company, I am 21, and my position is junior Web developer. It is just so happened (and I hate it), that I get responsible for compliting one project, which is Social Networking travel web portal. I just started to program with .Net, before was programming on Java, so I do huge amount of stupid errors all around.
Spent 2 days to set Hibernate, but any examples I was trying to implement were not working (I know that there were my faults).
One error pulled me to the corner. I don't know what to do with that... was looking in tutorials etc. but have not find anything
some initial values:
I use NHibernate 1.2[b]
[b]my mapping file: User.hbm.xml
Here is the code:
<?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"> <class name="Model.User, Model" table="User"> <id name="Id" unsaved-value="0" column="id" type="System.Int32"> <generator class="native" /> </id> <property name="FirstName" column="firstName" type="System.String"/> <property name="Password" column="password" type="System.String" /> <property name="LastName" column="lastName" type="System.String"/> <property name="Sex" column="sex" type="System.String"/> <property name="City" column="city" type="System.String"/> <property name="Country" column="country" type="System.String"/> <property name="Address" column="address" type="System.String"/> <property name="Zip" column="zip" type="System.String"/> <property name="Email" column="email" type="System.String"/> <property name="PicturePath" column="picturePath" type="System.String"/> <property name="Birthday" column="birthday" type="System.String"/> <property name="Info" column="info" type="System.String"/> <property name="Hometown" column="hometown" type="System.String"/> <property name="IsAdmin" column="isAdmin" type="System.Boolean"/> </class> </hibernate-mapping>
For the code, I used source of http://www.beansoftware.com/ASP.NET-Tutorials/Examples/NHibernate-Log4Net.zip
It is from article: http://www.beansoftware.com/ASP.NET-Tutorials/NHibernate-Log4Net.aspx
And I got exception when I save my object, which is
[SqlException (0x80131904): Incorrect syntax near the keyword 'User'.] System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +862234 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +739110 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +188 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1956 System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +31 System.Data.SqlClient.SqlDataReader.get_MetaData() +62 System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +297 System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +903 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +132 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32 System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +122 System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +12 System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader() +9 NHibernate.Impl.BatcherImpl.ExecuteReader(IDbCommand cmd) +68 NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object[] fields, Boolean[] notNull, SqlCommandInfo sql, Object obj, ISessionImplementor session) +532
[ADOException: could not insert: [Model.User][SQL: INSERT INTO User (firstName, password, lastName, sex, city, country, address, zip, email, picturePath, birthday, info, hometown, isAdmin) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]] NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object[] fields, Boolean[] notNull, SqlCommandInfo sql, Object obj, ISessionImplementor session) +1141 NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object[] fields, Object obj, ISessionImplementor session) +359 NHibernate.Impl.ScheduledIdentityInsertion.Execute() +100 NHibernate.Impl.SessionImpl.Execute(IExecutable executable) +169 NHibernate.Impl.SessionImpl.DoSave(Object theObj, EntityKey key, IEntityPersister persister, Boolean replicate, Boolean useIdentityColumn, CascadingAction cascadeAction, Object anything) +932 NHibernate.Impl.SessionImpl.DoSave(Object obj, Object id, IEntityPersister persister, Boolean useIdentityColumn, CascadingAction cascadeAction, Object anything) +529 NHibernate.Impl.SessionImpl.SaveWithGeneratedIdentifier(Object obj, CascadingAction action, Object anything) +427 NHibernate.Impl.SessionImpl.Save(Object obj) +282 _Default.register_Click(Object sender, EventArgs e) in c:\projects\NHibernate_Test\Default.aspx.cs:26 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102
I belive that main problem is
[color=red][ADOException: could not insert: [Model.User][SQL: INSERT INTO User (firstName, password, lastName, sex, city, country, address, zip, email, picturePath, birthday, info, hometown, isAdmin) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]][/color]
So, I assumed, that my objec replicated incorrectly, perhaps I made a mistake somewhere. But I can't find it...
Just in case, here is my object class:
Code: namespace Model { public class User { private Int32 id = 0; private string email=" "; private string password=""; private string firstName=""; private string lastName=""; private string sex=""; private string city=""; private string country=""; private string zip=""; private string address=""; private string picturePath=""; private string birthday=""; private string info=""; private string hometown=""; private bool isAdmin=false;
public virtual int Id { get { return id; } set { id = value; } }
public virtual string PicturePath { get { return picturePath; } set { picturePath = value; } }
public virtual string Birthday { get { return birthday; } set { birthday = value; } }
public virtual string Info { get { return info; } set { info = value; } }
public virtual string Hometown { get { return hometown; } set { hometown = value; } }
public virtual bool IsAdmin { get { return isAdmin; } set { isAdmin = value; } }
public User() {
}
public virtual string Email { get { return email; } set { email = value; } }
public virtual string Password { get { return password; } set { password = value; } }
public virtual string FirstName { get { return firstName; } set { firstName = value; } }
public virtual string LastName { get { return lastName; } set { lastName = value; } }
public virtual string Sex { get { return sex; } set { sex = value; } }
public virtual string City { get { return city; } set { city = value; } }
public virtual string Country { get { return country; } set { country = value; } }
public virtual string Zip { get { return zip; } set { zip = value; } }
public virtual string Address { get { return address; } set { address = value; } } } }
I use MS SQL Express 2005
Don't know how to do that:
Debug level Hibernate log excerpt:
I have log4net connected, not sure what I need to do.
And I have one more question: may be I should not use ORM for this project? (project is almost the same as a myspace, just without ability to adjust the page look and feel & its multimedia functions). I am stocked, I tryed DNN, but was failed with that. may be I just need to use DataSets and so on...? Sorry for one more Dummy post.
[url][/url]
Thank you very much for reading, Appresiate any help
|
|