Is this a RhinoSecurity, Nhibernate bug or am I just being a bonehead?

29 views
Skip to first unread message

Firefly

unread,
Nov 29, 2009, 3:35:58 AM11/29/09
to Rhino Tools Dev
I have uploaded the file into the file pool that will throw an
exception that say something like this...

NHibernate.MappingException was unhandled
Message="An association from the table Permissions refers to an
unmapped class: Rhino.Security.IUser"
Source="NHibernate"


The source is a modified version of the tutorial by Artur that can be
found here http://weblogs.asp.net/arturtrosin/archive/2009/04/02/rhino-tools-rhino-security-guide.aspx

The relevance part of this error come from this part of the source

internal class NHibernateDbSchemaGeneration :
INHibernateInitializationAware
{
public void BeforeInitialization()
{
}

public void Configured(Configuration cfg)
{
//new SchemaExport(cfg).Create(true, true);

var cfg1 = new Configuration();
cfg1.Configure();

//why is that if I am using my own Configuration file I get
that error?
var db = new SchemaExport(cfg1);
db.Create(true, true);
}

public void Initialized(Configuration cfg, ISessionFactory
sessionFactory)
{
}
}


The error only happen when I created my own configuration object and
not when I use the cfg object that got passed in by the container.

I looked in the watch windows and base on my limited knowledge they
look very much the same. Is there something else that I need to do in
creating a new configuration object?
it probably something simple but fundamental that I am missing. This
set up have worked for me before. I only got an error today when I try
to incorporate Rhino into my project.

Ayende Rahien

unread,
Nov 29, 2009, 3:47:29 AM11/29/09
to rhino-t...@googlegroups.com
I think that you forgot to user Security.InitializeConfiguration<YourUserImpl>(cfg)


--

You received this message because you are subscribed to the Google Groups "Rhino Tools Dev" group.
To post to this group, send email to rhino-t...@googlegroups.com.
To unsubscribe from this group, send email to rhino-tools-d...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rhino-tools-dev?hl=en.



Hoang Tang

unread,
Nov 29, 2009, 4:53:37 AM11/29/09
to rhino-t...@googlegroups.com
I got it to work! Yay!

However there is some substantial change of how RhinoSecurity is
suppose to set up. The example that Artur use an older version of
RhinoSecurity so Security.InitializeConfiguration<YourUserImpl>(cfg)
wasn't available then.

If Security.InitializeConfiguration<YourUserImpl>(cfg) is used then
there is no need to Include the RhinoSecurity assembly into the
hibernate config file. In fact doing so will resulted in a duplicate
mapping error.
I actually got it set up correctly the first time.

However I couldn't get it to work because I used
SecurityTableStructure.Schema this is the part that I don't really
understand what is all that require if I used this instead of
SecurityTableStructure.Prefix. If somebody could explain the different
that would be great.

Anyway it's working when I changed to SecurityTableStructure.Prefix.
It's also worth noting that SchemaUpdate will fail silently(which sent
me on a wild goose chase) while SchemaExport will throw an exception
when I tried to use SecurityTableStructure.Schema


Here is the exception that got throw when I attempted to do a
SchemaExport with the SecurityTableStructure.Schema settting.

NHibernate.HibernateException was unhandled
Message="The specified schema name \"security\" either does not
exist or you do not have permission to use it."
Source="NHibernate"
StackTrace:
at NHibernate.Tool.hbm2ddl.SchemaExport.Execute(Action`1
scriptAction, Boolean export, Boolean justDrop)
at NHibernate.Tool.hbm2ddl.SchemaExport.Execute(Boolean script,
Boolean export, Boolean justDrop)
at NHibernate.Tool.hbm2ddl.SchemaExport.Create(Boolean script,
Boolean export)
at RhinoSecurity.Program.Main(String[] args) in
C:\Users\Hummy\Desktop\example\RhinoSecNhSetup\RhinoSecurity\RhinoSecurity\Program.cs:line
34
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.Data.SqlClient.SqlException
Message="The specified schema name \"security\" either does not
exist or you do not have permission to use it."
Source=".Net SqlClient Data Provider"
ErrorCode=-2146232060
Class=16
LineNumber=1
Number=2760
Procedure=""
Server="localhost\\SQLEXPRESS"
State=1
StackTrace:
at System.Data.SqlClient.SqlConnection.OnError(SqlException
exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject
stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior
runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream,
BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject
stateObj)
at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String
methodName, Boolean async)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult
result, String methodName, Boolean sendToPipe)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at NHibernate.Tool.hbm2ddl.SchemaExport.Execute(Action`1
scriptAction, Boolean export, Boolean throwOnError, TextWriter
exportOutput, IDbCommand statement, String sql)
at NHibernate.Tool.hbm2ddl.SchemaExport.Execute(Action`1
scriptAction, Boolean export, Boolean justDrop, IDbConnection
connection, TextWriter exportOutput)
at NHibernate.Tool.hbm2ddl.SchemaExport.Execute(Action`1
scriptAction, Boolean export, Boolean justDrop)
InnerException:

Ayende Rahien

unread,
Nov 29, 2009, 12:50:02 PM11/29/09
to rhino-t...@googlegroups.com
Hoang,
This difference between schema & prefix is how RS will refer to the tables.
If you use schema, then the tables will be secruity.Permissions (which requires to manually create the schemas).
If you use prefix, then the table swill be security_Permissions.

Hoang Tang

unread,
Nov 29, 2009, 7:44:23 PM11/29/09
to rhino-t...@googlegroups.com
Oren,

Thanks for the quick reply. So what so particular about the schema beside the obvious naming convention different that prevent NHibernate from generating the table automatically? Is this by design?

On a side note NHProf is a great troubleshooting tool. Being able to see what kind of query got generated, when they are hitting the database, along with all the sql parameter is just great! In NHProf I can see that NHibernate attempted to generate security.Permission database and it fail. Though I didn't know why, it certainly help direct me on the right path and this is just one particular case...

Ayende Rahien

unread,
Nov 30, 2009, 4:54:05 AM11/30/09
to rhino-t...@googlegroups.com
Hoang,
The reason is to avoid name clashes with your existing database. You might have a Permissions table already.
Reply all
Reply to author
Forward
0 new messages