These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: help SQL: VALUES (?, ?, ?, ?, ?, ?, ?, ?);
PostPosted: Sun Sep 14, 2008 8:05 pm 
Newbie

Joined: Sun Sep 14, 2008 7:58 pm
Posts: 2
I am a newbie with nhibernate, trying to write a basic test app to learn how it works.

Can anyone help me figure out why the generated insert statement is coming up with all ?s for the values?

{"could not insert: [TicketRegistration.Person][SQL: INSERT INTO Persons (EmailAddress, FirstName, LastName, Address, Zip, Phone, EveningPhone, BirthDate) VALUES (?, ?, ?, ?, ?, ?, ?, ?); select SCOPE_IDENTITY()]"}


Here is my code, but I don't think this matters much. I am using a helper class to create the session.
Dim session As ISession = NHibernateHelper.GetCurrentSession()

Dim tx As ITransaction = session.BeginTransaction()

Dim p As Person = New Person
p.Address = "123"
p.FirstName = "Bill"
p.LastName = "Clinton"
p.BirthDate = new date(1975,1,1)

session.Save(p)
tx.Commit()

NHibernateHelper.CloseSession()


Mapping file

<?xml version="1.0" encoding="utf-8" ?>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="TicketRegistration" namespace="TicketRegistration">

<!-- more mapping info here -->
<class name="Person" table="Persons">
<id name="Id">
<generator class="identity" />
</id>
<property name="EmailAddress" column="EmailAddress" />
<property name="FirstName" />
<property name="LastName" />
<property name="Address" />
<property name="Zip" />
<property name="Phone" />
<property name="EveningPhone" />
<property name="BirthDate" />
</class>


</hibernate-mapping>


config file
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">

<session-factory>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.connection_string">server=cmayt61p;Initial Catalog=accounts;User Id=accountsuser;Password=accounts;</property>
<property name="show_sql">true</property>

<mapping resource="Person.hbm.xml" assembly="TicketRegistration" />
</session-factory>
</hibernate-configuration>





Namespace TicketRegistration

Public Class Person

Private ciId As Integer
Private csEmailAddress As String
Private csFirstName As String
Private csLastName As String
Private csAddress As String
Private csZip As String
Private csPhone As String
Private csEveningPhone As String
Private cdBirthDate As Date

Public Overridable Property Id() As Integer
Get
Return ciId
End Get
Set(ByVal value As Integer)
ciId = value
End Set
End Property

Public Overridable Property EmailAddress() As String
Get
Return Me.csEmailAddress
End Get
Set(ByVal value As String)
Me.csEmailAddress = value
End Set
End Property

Public Overridable Property FirstName() As String
Get
Return Me.csFirstName
End Get
Set(ByVal value As String)
Me.csFirstName = value
End Set
End Property

Public Overridable Property LastName() As String
Get
Return Me.csLastName
End Get
Set(ByVal value As String)
Me.csLastName = value
End Set
End Property

Public Overridable Property Address() As String
Get
Return Me.csAddress
End Get
Set(ByVal value As String)
Me.csAddress = value
End Set
End Property

Public Overridable Property Zip() As String
Get
Return Me.csZip
End Get
Set(ByVal value As String)
Me.csZip = value
End Set
End Property

Public Overridable Property Phone() As String
Get
Return Me.csPhone
End Get
Set(ByVal value As String)
Me.csPhone = value
End Set
End Property

Public Overridable Property EveningPhone() As String
Get
Return Me.csEveningPhone
End Get
Set(ByVal value As String)
Me.csEveningPhone = value
End Set
End Property

Public Overridable Property BirthDate() As Date
Get
Return Me.cdBirthDate
End Get
Set(ByVal value As Date)
cdBirthDate = value
End Set
End Property



End Class

End Namespace


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 15, 2008 2:52 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Quote:
{"could not insert: [TicketRegistration.Person][SQL: INSERT INTO Persons (EmailAddress, FirstName, LastName, Address, Zip, Phone, EveningPhone, BirthDate) VALUES (?, ?, ?, ?, ?, ?, ?, ?); select SCOPE_IDENTITY()]"}


The "?" are placeholders for the SQL command parameters. That's "just" logging. Depending on the logging level and if show_sql is set to true, you can see more information.

Can you post the exception details ? Check the inner exception for more information.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Oops, Im dumb
PostPosted: Mon Sep 15, 2008 3:19 am 
Newbie

Joined: Sun Sep 14, 2008 7:58 pm
Posts: 2
Oops, I'm dumb and deserve to be mocked.

The inner exception couldn't have been more clear as to my problem: permissions on the database table.

Fixed it and it's working.

Thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.