读书人

NHibernate有关问题

发布时间: 2012-01-20 18:53:53 作者: rapoo

NHibernate问题?
create table TBL_USER_INFO
(
USER_ID VARCHAR2(16) not null,
USER_NAME VARCHAR2(50) not null,
USER_PASSWORD VARCHAR2(32) not null,
DEPARTMENT_CODE VARCHAR2(16) not null,
SUBDEPARTMENT_CODE VARCHAR2(16),
STATUS_CODE CHAR(1) not null,
PASSWORD_STATUS_CODE CHAR(1),
CREATE_DATE DATE not null
)
alter table TBL_USER_INFO
add constraint FK_DEPARTMENT_CODE_USER_INFO foreign key (SUBDEPARTMENT_CODE, DEPARTMENT_CODE)
references TBL_SUBDEPARTMENT (SUBDEPARTMENT_CODE, DEPARTMENT_CODE);


Public Class user

Private _id As String
Private _userName As String
Private _password As String
Private _departCode As String
Private _subDepartCode As String
Private _statusCode As String
Private _passWordSign As String
Private _createDate As DateTime

Public Property ID() As String
Get
Return _id
End Get
Set(ByVal Value As String)
If Value <> _id Then
If Value = " " Then
_id = Nothing
Else
_id = Value
End If
End If
End Set
End Property

Public Property UserName() As String


Get
Return _userName
End Get
Set(ByVal Value As String)
If Value <> _userName Then
If Value = " " Then
_userName = Nothing
Else
_userName = Value
End If
End If
End Set
End Property

Public Property PassWord() As String
Get
Return _password
End Get
Set(ByVal Value As String)
If Value <> _password Then
If Value = " " Then
_password = Nothing
Else
_password = Value
End If
End If
End Set
End Property

Public Property DepartCode() As String
Get
Return _departCode
End Get
Set(ByVal Value As String)
If Value <> _departCode Then


If Value = " " Then
_departCode = Nothing
Else
_departCode = Value
End If
End If
End Set
End Property

Public Property SubDepartCode() As String
Get
Return _subDepartCode
End Get
Set(ByVal Value As String)
If Value <> _subDepartCode Then
If Value = " " Then
_subDepartCode = Nothing
Else
_subDepartCode = Value
End If
End If
End Set
End Property

Public Property StatusCode() As String
Get
Return _statusCode
End Get
Set(ByVal Value As String)
If Value <> _statusCode Then
If Value = " " Then
_statusCode = Nothing
Else


_statusCode = Value
End If
End If
End Set
End Property

Public Property PassWordSign() As String
Get
Return _passWordSign
End Get
Set(ByVal Value As String)
If Value <> _passWordSign Then
If Value = " " Then
_passWordSign = Nothing
Else
_passWordSign = Value
End If
End If
End Set
End Property

Public Property CreateDate() As DateTime
Get
Return _createDate
End Get
Set(ByVal Value As DateTime)
If Value <> _createDate Then
If CType(Value, String) = " " Then
_createDate = Nothing
Else
_createDate = Value
End If
End If


End Set
End Property
End Class

<?xml version= "1.0 " encoding= "utf-8 " ?>
<hibernate-mapping xmlns= "urn:nhibernate-mapping-2.0 ">
<class name= "NHibernateDemo.user, NHibernateDemo " table= "TBL_USER_INFO ">
<id name= "ID " column= "USER_ID " type= "String " length= "16 " ">
<generator class= "assigned " />
</id>
<property name= "UserName " column= "USER_NAME " type= "String " length= "50 " not-null= "true " />
<property name= "PassWord " column= "USER_PASSWORD " type= "String " length= "32 " not-null= "true " />
<property name= "DepartCode " column= "DEPARTMENT_CODE " type= "String " length= "16 " not-null= "true " />
<property name= "CreateDate " column= "CREATE_DATE " type= "DateTime " not-null= "true " />
<property name= "SubDepartCode " column= "SUBDEPARTMENT_CODE " type= "String " length= "16 " />
<property name= "StatusCode " column= "STATUS_CODE " type= "String " length= "1 " not-null= "true " />
<property name= "PassWordSign " column= "PASSWORD_STATUS_CODE " type= "String " length= "1 "/>

</class>
</hibernate-mapping>


<?xml version= "1.0 " encoding= "utf-8 "?>
<configuration>
<configSections>
<section name= "nhibernate " type= "System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089 " />
<section name= "log4net " type= "log4net.Config.Log4NetConfigurationSectionHandler,log4net " />
</configSections>
<nhibernate>
<add key= "hibernate.connection.provider " value= "NHibernate.Connection.DriverConnectionProvider " />
<add key= "hibernate.dialect " value= "NHibernate.Dialect.Oracle9Dialect " />
<add key= "hibernate.connection.driver_class " value= "NHibernate.Driver.OracleClientDriver " />
<add key= "hibernate.connection.connection_string " value= "user id=caac;data source=orcl08;password=caac;max pool size=300; persist security info=true "/>
</nhibernate>
<!-- This section contains the log4net configuration settings -->
<log4net debug= "true ">
<!-- Define some output appenders -->
<appender name= "rollingFile " type= "log4net.Appender.RollingFileAppender,log4net ">
<param name= "File " value= "log.txt " />


<param name= "AppendToFile " value= "true " />
<param name= "RollingStyle " value= "Date " />
<param name= "DatePattern " value= "yyyy.MM.dd " />
<param name= "StaticLogFileName " value= "true " />
<layout type= "log4net.Layout.PatternLayout,log4net ">
<param name= "ConversionPattern " value= "%d [%t] %-5p %c [%x] <%X{auth}> - %m%n " />
</layout>
</appender>
<!-- Setup the root category, add the appenders and set the default priority -->
<root>
<priority value= "ERROR " />
<appender-ref ref= "rollingFile " />
</root>
</log4net>
</configuration>


Imports NHibernate.Cfg
Imports NHibernate
Imports NHibernate.Tool.hbm2ddl

Public Class UserDAO

Dim objCfg As New Configuration
Dim objUser As New user


Public Sub create()

objCfg.AddAssembly( "NHibernateDemo ")
Dim factory As ISessionFactory = objCfg.BuildSessionFactory()
Dim session As ISession = factory.OpenSession()
Dim transaction As ITransaction = session.BeginTransaction()

objUser.ID = "guodukeji "
objUser.UserName = "guo "
objUser.PassWord = "test "
objUser.CreateDate = Now.Date

objUser.DepartCode = "SYSTEM "
objUser.SubDepartCode = "SYSTEM "
objUser.PassWordSign = "U "
objUser.StatusCode = "Y "


Try
session.Save(objUser)
transaction.Commit()
Catch ex As Exception
transaction.Rollback()
Console.WriteLine(ex.Message & ex.Source)
End Try



End Sub

End Class


运行到session.Save(objUser),就抛出异常Could not save object??
刚接触,搞不明白!!

哪位仁兄帮看一下,谢谢!

[解决办法]
具体原因不清楚,但你可以查看抛出异常ex的InnerException属性,这样应该可以得到更进一步的错误提示。
[解决办法]
帮顶
[解决办法]
正在学习

读书人网 >VB Dotnet

热点推荐