-->
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.  [ 12 posts ] 
Author Message
 Post subject: Retrieve data from oracle
PostPosted: Tue Dec 06, 2005 9:14 am 
Newbie

Joined: Tue Dec 06, 2005 8:47 am
Posts: 16
Location: London
I am new to using NHibernate, and have the following error. I have run a test using SQL Server, and the quickstart, and it works fine. I then went on to create a table in the oracle database with 4 fields (User_ID, Firstname, Lastname, Telephone). I can save data to the database fine, but when i try to retrieve the data, i get errors. If i retrieve a list, it reports that the find cannot be performed, but it does bring back the user_id fields, but not the rest of the data. If i try an individual record, it return an error "could not load Users". Can anybody help. I am using the oracle dialect with an oracle 9i database.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 07, 2005 11:09 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
Can you give more details about your problem? (your config settings, the mapping, the log with the full exception trace...)

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 08, 2005 11:49 am 
Newbie

Joined: Tue Dec 06, 2005 8:47 am
Posts: 16
Location: London
The database is Oracle 9i. The oracle driver is the oracle for .net version 9.0.7

The configuration that i am using is as follows:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.0" >
<session-factory name="NHibernate.Test">
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.OracleClientDriver</property>
<property name="connection.connection_string">Server=test; UID=test1; PWD=password;</property>
<property name="dialect">NHibernate.Dialect.Oracle9Dialect</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>

The mapping file is as follows

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="NHibernateTest.User, NHibernateTest" table="users">
<id name="Id" column="LogonId" type="String" length="20">
<generator class="assigned" />
</id>
<property name="UserName" column= "Name" type="String" length="40"/>
<property name="Password" type="String" length="20"/>
<property name="EmailAddress" type="String" length="40"/>
<property name="LastLogon" type="DateTime"/>
</class>
</hibernate-mapping>

The following is the stack trace:

at NHibernate.Persister.GetSetHelper_NHibernateTest_Users.SetPropertyValues(Object obj, Object[] values)
at NHibernate.Persister.AbstractEntityPersister.SetPropertyValues(Object obj, Object[] values)
at NHibernate.Impl.SessionImpl.InitializeEntity(Object obj)
at NHibernate.Loader.Loader.InitializeEntitiesAndCollections(IList hydratedObjects, Object resultSetId, ISessionImplementor session)
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
at NHibernate.Loader.Loader.LoadEntity(ISessionImplementor session, Object[] values, IType[] types, Object optionalObject, Object optionalID)
at NHibernate.Loader.Loader.LoadEntity(ISessionImplementor session, Object id, IType identifierType, Object optionalObject, Object optionalIdentifier)
at NHibernate.Loader.EntityLoader.Load(ISessionImplementor session, Object id, Object optionalObject, Object optionalId)
at NHibernate.Loader.EntityLoader.Load(ISessionImplementor session, Object id, Object optionalObject)
at NHibernate.Persister.EntityPersister.Load(Object id, Object optionalObject, LockMode lockMode, ISessionImplementor session)

Dont know if this helps, or if you require more information. As mentioned, i am new at using open source software. I have tried to use the source to debug the error, but cannot seem to compile this on my side. Please bear with me if i did not send enough information. I am very keen to prove that we can use nhibernate instead of the current ado.net. We are in the process of making some major changes in our development framework, and one of these is to move to a object persistence model.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 08, 2005 12:22 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
jpremji wrote:
<class name="NHibernateTest.User, NHibernateTest" table="users">


So the error is "could not load Users"? The mapping appears to be "User" not "Users". Unless the post is a typo, that could be the problem.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 08, 2005 2:24 pm 
Newbie

Joined: Tue Dec 06, 2005 8:47 am
Posts: 16
Location: London
Sorry that was the wrong mapping file. I have 2 versions, one for SQL Server and the other for Oracle. Here is the version for Oracle

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="NHibernateTest.Users, NHibernateTest" table="Users">
<id name="UserID" column="USER_ID" type="Int32">
<generator class="sequence">
<param name="sequence">uid_sequence</param>
</generator>
</id>
<property column="Firstname" type="String" name="Firstname" />
<property column="Lastname" type="String" name="Lastname" />
<property column="Telephone" type="Decimal" name="Telephone" />

</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 08, 2005 2:25 pm 
Newbie

Joined: Tue Dec 06, 2005 8:47 am
Posts: 16
Location: London
Just to add tis is the function call

Dim cfg As New Configuration
cfg.Configure()
cfg.AddAssembly("NHibernateTest")

Dim factory As ISessionFactory = cfg.BuildSessionFactory()
Dim session As ISession = factory.OpenSession()
Dim trx As ITransaction = session.BeginTransaction()
Dim User As Users

User = CType(session.Load(GetType(Users), 2), Users)
Return User.Firstname

session.Disconnect()


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 10, 2005 7:12 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
Make sure that your mapping file is loaded by NHibernate (use log4net logs...)

The most common reason is forgetting to set it as "Embedded Resource".

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 10, 2005 8:31 am 
Newbie

Joined: Tue Dec 06, 2005 8:47 am
Posts: 16
Location: London
Thanks for that. i have set the mapping file as embedded resource, and can insert a new row in the database fine. i can even get the list of entries with only the ID field displayed, but not the other fields. This is where the error seems to be occuring.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 10, 2005 1:35 pm 
Newbie

Joined: Tue Dec 06, 2005 8:47 am
Posts: 16
Location: London
Here is the log generated by log4net. Hope this helps.

17:31:16.620 [3596] INFO NHibernate.Cfg.Configuration - processing one-to-many association mappings
17:31:16.670 [3596] INFO NHibernate.Cfg.Configuration - processing one-to-one association property references
17:31:16.670 [3596] INFO NHibernate.Cfg.Configuration - processing foreign key constraints
17:31:16.690 [3596] INFO NHibernate.Dialect.Dialect - Using dialect: NHibernate.Dialect.Oracle9Dialect
17:31:16.690 [3596] INFO NHibernate.Cfg.SettingsFactory - use outer join fetching: True
17:31:16.690 [3596] INFO NHibernate.Connection.ConnectionProviderFactory - Intitializing connection provider: NHibernate.Connection.DriverConnectionProvider
17:31:16.690 [3596] INFO NHibernate.Connection.ConnectionProvider - Configuring ConnectionProvider
17:31:16.710 [3596] INFO NHibernate.Cfg.SettingsFactory - Optimize cache for minimal puts: False
17:31:16.710 [3596] INFO NHibernate.Cfg.SettingsFactory - echoing all SQL to stdout
17:31:16.720 [3596] INFO NHibernate.Cfg.SettingsFactory - Query language substitutions: {}
17:31:16.720 [3596] INFO NHibernate.Cfg.SettingsFactory - cache provider: NHibernate.Cache.HashtableCacheProvider
17:31:16.720 [3596] INFO NHibernate.Cfg.Configuration - instantiating and configuring caches
17:31:16.740 [3596] INFO NHibernate.Impl.SessionFactoryImpl - building session factory
17:31:16.740 [3596] DEBUG NHibernate.Impl.SessionFactoryImpl - instantiating session factory with properties: {show_sql=true, connection.provider=NHibernate.Connection.DriverConnectionProvider, dialect=NHibernate.Dialect.Oracle9Dialect, connection.driver_class=NHibernate.Driver.OracleClientDriver, hibernate.session_factory_name=NHibernate.Test, hibernate.use_reflection_optimizer=True, hibernate.connection.connection_string=Server=ezlap1; UID=schroderweb; PWD=password;, hibernate.connection.driver_class=NHibernate.Driver.OracleClientDriver, connection.connection_string=Server=ezlap1; UID=schroderweb; PWD=password;, hibernate.connection.provider=NHibernate.Connection.DriverConnectionProvider, hibernate.dialect=NHibernate.Dialect.Oracle9Dialect, hibernate.show_sql=true}
17:31:16.821 [3596] DEBUG NHibernate.Persister.GetSetHelperFactory - Init compiler for class NHibernateApp.Users
17:31:16.821 [3596] DEBUG NHibernate.Persister.GetSetHelperFactory - Adding referenced assembly d:\work\dotnet projects\nhibernate\nhibernateapp\bin\nhibernate.dll
17:31:16.821 [3596] DEBUG NHibernate.Persister.GetSetHelperFactory - Adding referenced assembly D:\Work\dotnet projects\NHibernate\NHibernateApp\bin\NHibernateApp.exe
17:31:16.831 [3596] DEBUG NHibernate.Persister.GetSetHelperFactory - Adding referenced assembly c:\windows\microsoft.net\framework\v1.1.4322\mscorlib.dll
17:31:17.031 [3596] DEBUG NHibernate.Persister.GetSetHelperFactory - Compiled ok:
using System;
using NHibernate.Property;
namespace NHibernate.Persister {
public class GetSetHelper_NHibernateApp_Users : IGetSetHelper {
ISetter[] setters;
IGetter[] getters;
public GetSetHelper_NHibernateApp_Users(ISetter[] setters, IGetter[] getters) {
this.setters = setters;
this.getters = getters;
}
public void SetPropertyValues(object obj, object[] values) {
NHibernateApp.Users t = (NHibernateApp.Users)obj;
t.Telephone = values[0] == null ? new System.Int32() : (System.Int32)values[0];
t.Lastname = (System.String)values[1];
t.Firstname = (System.String)values[2];
}
public object[] GetPropertyValues(object obj) {
NHibernateApp.Users t = (NHibernateApp.Users)obj;
object[] ret = new object[3];
ret[0] = t.Telephone;
ret[1] = t.Lastname;
ret[2] = t.Firstname;
return ret;
}
}
}

17:31:17.072 [3596] DEBUG NHibernate.Impl.SessionFactoryObjectFactory - initializing class SessionFactoryObjectFactory
17:31:17.072 [3596] DEBUG NHibernate.Impl.SessionFactoryObjectFactory - registered: f31c6efb673e4ae7b3ac51e8c32a868c(NHibernate.Test)
17:31:17.072 [3596] INFO NHibernate.Impl.SessionFactoryObjectFactory - Factory name:NHibernate.Test
17:31:17.072 [3596] DEBUG NHibernate.Impl.SessionFactoryImpl - Instantiated session factory
17:31:17.082 [3596] DEBUG NHibernate.Impl.SessionImpl - opened session
17:31:17.082 [3596] DEBUG NHibernate.Transaction.AdoTransaction - begin
17:31:17.082 [3596] DEBUG NHibernate.Connection.DriverConnectionProvider - Obtaining IDbConnection from Driver
17:31:19.431 [3596] DEBUG NHibernate.Impl.SessionImpl - loading [Users#2]
17:31:19.431 [3596] DEBUG NHibernate.Impl.SessionImpl - attempting to resolve [Users#2]
17:31:19.431 [3596] DEBUG NHibernate.Impl.SessionImpl - object not resolved in any cache [NHibernateApp.Users#2]
17:31:19.431 [3596] DEBUG NHibernate.Persister.EntityPersister - Materializing entity: NHibernateApp.Users#2
17:31:19.481 [3596] DEBUG NHibernate.Impl.BatcherImpl - Opened new IDbCommand, open IDbCommands :1
17:31:19.481 [3596] DEBUG NHibernate.Impl.BatcherImpl - Building an IDbCommand object for the SqlString: SELECT users0_.USER_ID as USER_ID0_, users0_.Telephone as Telephone0_, users0_.Lastname as Lastname0_, users0_.Firstname as Firstname0_ FROM Users users0_ WHERE users0_.USER_ID=:USER_ID
17:31:19.491 [3596] INFO NHibernate.Loader.Loader - SELECT users0_.USER_ID as USER_ID0_, users0_.Telephone as Telephone0_, users0_.Lastname as Lastname0_, users0_.Firstname as Firstname0_ FROM Users users0_ WHERE users0_.USER_ID=:p0
17:31:19.491 [3596] DEBUG NHibernate.SQL - SELECT users0_.USER_ID as USER_ID0_, users0_.Telephone as Telephone0_, users0_.Lastname as Lastname0_, users0_.Firstname as Firstname0_ FROM Users users0_ WHERE users0_.USER_ID=:p0
17:31:19.491 [3596] DEBUG NHibernate.SQL - SELECT users0_.USER_ID as USER_ID0_, users0_.Telephone as Telephone0_, users0_.Lastname as Lastname0_, users0_.Firstname as Firstname0_ FROM Users users0_ WHERE users0_.USER_ID=:p0
17:31:19.551 [3596] DEBUG NHibernate.Impl.BatcherImpl - Opened Reader, open Readers :1
17:31:19.551 [3596] DEBUG NHibernate.Loader.Loader - processing result set
17:31:19.571 [3596] DEBUG NHibernate.Loader.Loader - result row: 2
17:31:19.581 [3596] DEBUG NHibernate.Loader.Loader - Initializing object from DataReader: 2
17:31:19.591 [3596] DEBUG NHibernate.Loader.Loader - Hydrating entity: NHibernateApp.Users#2
17:31:19.612 [3596] DEBUG NHibernate.Loader.Loader - done processing result set (1 rows)
17:31:19.612 [3596] DEBUG NHibernate.Impl.BatcherImpl - Closed Reader, open Readers :0
17:31:19.612 [3596] DEBUG NHibernate.Impl.BatcherImpl - Closed IDbCommand, open IDbCommands :0
17:31:19.612 [3596] DEBUG NHibernate.Loader.Loader - total objects hydrated: 1
17:31:19.612 [3596] DEBUG NHibernate.Impl.SessionImpl - resolving associations for: [NHibernateApp.Users#2]
17:31:20.626 [3596] DEBUG NHibernate.Util.ADOExceptionReporter - could not load: [NHibernateApp.Users#2]
System.InvalidCastException: Specified cast is not valid.
at NHibernate.Persister.GetSetHelper_NHibernateApp_Users.SetPropertyValues(Object obj, Object[] values)
at NHibernate.Persister.AbstractEntityPersister.SetPropertyValues(Object obj, Object[] values)
at NHibernate.Impl.SessionImpl.InitializeEntity(Object obj)
at NHibernate.Loader.Loader.InitializeEntitiesAndCollections(IList hydratedObjects, Object resultSetId, ISessionImplementor session)
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
at NHibernate.Loader.Loader.LoadEntity(ISessionImplementor session, Object[] values, IType[] types, Object optionalObject, Object optionalID)
at NHibernate.Loader.Loader.LoadEntity(ISessionImplementor session, Object id, IType identifierType, Object optionalObject, Object optionalIdentifier)
at NHibernate.Loader.EntityLoader.Load(ISessionImplementor session, Object id, Object optionalObject, Object optionalId)
at NHibernate.Loader.EntityLoader.Load(ISessionImplementor session, Object id, Object optionalObject)
at NHibernate.Persister.EntityPersister.Load(Object id, Object optionalObject, LockMode lockMode, ISessionImplementor session)
17:31:20.636 [3596] WARN NHibernate.Util.ADOExceptionReporter - System.InvalidCastException: Specified cast is not valid.
at NHibernate.Persister.GetSetHelper_NHibernateApp_Users.SetPropertyValues(Object obj, Object[] values)
at NHibernate.Persister.AbstractEntityPersister.SetPropertyValues(Object obj, Object[] values)
at NHibernate.Impl.SessionImpl.InitializeEntity(Object obj)
at NHibernate.Loader.Loader.InitializeEntitiesAndCollections(IList hydratedObjects, Object resultSetId, ISessionImplementor session)
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
at NHibernate.Loader.Loader.LoadEntity(ISessionImplementor session, Object[] values, IType[] types, Object optionalObject, Object optionalID)
at NHibernate.Loader.Loader.LoadEntity(ISessionImplementor session, Object id, IType identifierType, Object optionalObject, Object optionalIdentifier)
at NHibernate.Loader.EntityLoader.Load(ISessionImplementor session, Object id, Object optionalObject, Object optionalId)
at NHibernate.Loader.EntityLoader.Load(ISessionImplementor session, Object id, Object optionalObject)
at NHibernate.Persister.EntityPersister.Load(Object id, Object optionalObject, LockMode lockMode, ISessionImplementor session)
17:31:20.636 [3596] ERROR NHibernate.Util.ADOExceptionReporter - Specified cast is not valid.
17:31:20.636 [3596] ERROR NHibernate.ADOException - could not load: [NHibernateApp.Users#2]
System.InvalidCastException: Specified cast is not valid.
at NHibernate.Persister.GetSetHelper_NHibernateApp_Users.SetPropertyValues(Object obj, Object[] values)
at NHibernate.Persister.AbstractEntityPersister.SetPropertyValues(Object obj, Object[] values)
at NHibernate.Impl.SessionImpl.InitializeEntity(Object obj)
at NHibernate.Loader.Loader.InitializeEntitiesAndCollections(IList hydratedObjects, Object resultSetId, ISessionImplementor session)
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
at NHibernate.Loader.Loader.LoadEntity(ISessionImplementor session, Object[] values, IType[] types, Object optionalObject, Object optionalID)
at NHibernate.Loader.Loader.LoadEntity(ISessionImplementor session, Object id, IType identifierType, Object optionalObject, Object optionalIdentifier)
at NHibernate.Loader.EntityLoader.Load(ISessionImplementor session, Object id, Object optionalObject, Object optionalId)
at NHibernate.Loader.EntityLoader.Load(ISessionImplementor session, Object id, Object optionalObject)
at NHibernate.Persister.EntityPersister.Load(Object id, Object optionalObject, LockMode lockMode, ISessionImplementor session)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 11, 2005 8:41 am 
Newbie

Joined: Tue Dec 06, 2005 8:47 am
Posts: 16
Location: London
More information to help find the problem. I have now run nhibernate in debug mode, and managed to find the place where the error is taking place. I cannot seem to get passed this stage, and hope somebody else can help.

The error seems to occur in the NHibernate.Persister.AbstractEntityPersister.SetPropertyValues when calling the getset.SetPropertyValues(obj, values);

While debugging, i can confirm that the values are selected from the database, but fails when trying to set the class values with these values. I have tested using only the id field in the class, and this works fine.

And just to add, i finally decided to try this application using c# instead of vb.net. The result - it works fine in c#.

Hopefully this will help somebody find the reason why there is a problem in vb.net. I should have thought of this first, but hey you do learn along the way.

Looks like i am going to have to change my programming language for now, if i want to use nhibernate, probably gives me a reason to start working on c# instead. :roll:


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 12, 2005 9:39 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
You have telephone mapped as Decimal, but the field type is apparently Int32, looks like this is causing the problem.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 12, 2005 7:12 pm 
Newbie

Joined: Tue Dec 06, 2005 8:47 am
Posts: 16
Location: London
Thank you for that. I needed another pair of eyes to see that. I suppose i was to excited to get it working, i did not check the simple things. We do learn from school boy errors.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 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.