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: SchemaExport not deleting table
PostPosted: Thu Dec 21, 2006 5:00 am 
Newbie

Joined: Thu Dec 21, 2006 4:34 am
Posts: 13
I'm using the following code to recreate the database at the start of a test run:


schemaExport.Drop(false, true);
schemaExport.Create(true, true);

I'm using NHibernate 1.0.3 with SQL Server 2000 (sp4)

I've fired up sql profiler and see what appears to be the correct ddl statements being issued. In fact the ddl works as expected when the database is empty. The problem occurs on the second run. I get an exception of type HibernateException with the message: There is already an object named 'parkinglot' in the database.

This parkinglot object is a table. I've tried running in query analyzer the sql statement that queries sysobjects and [drop]s the table if it exists. This works fine once I first made sure the connection in query analyzer pointed to the actual database I am testing against (it didn't work if the connection was pointing at the master database for example).

The strange thing is I've used exactly the same NHibernate code to recreate another database that had a different set of objects without any problems.

Anyway, any help or pointers of how to diagnose / get a fix for this problem would be appreciated. Obviously I can supply my vs solution if that would help to get to the bottom of the problem.

Thanks in advance
Christian


Top
 Profile  
 
 Post subject: Permissions?
PostPosted: Thu Dec 21, 2006 2:58 pm 
Beginner
Beginner

Joined: Thu Apr 27, 2006 12:19 pm
Posts: 33
Location: Seattle, WA
From what you described it definately sounds like the tables are not getting dropped as expected - even though the DDL statements are being run. Does the account you are connecting to SQL Server from NHibernate have the appropriate permissions to drop tables?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 21, 2006 6:03 pm 
Newbie

Joined: Thu Dec 21, 2006 4:34 am
Posts: 13
Hey sneal, thanks for the reply.

I've just discovered that it was my bad. The problem was that I set the default schema to the name of my test database all well and good, BUT I got the connection string wrong so that the NHibernate connection was pointing to the wrong database.

The reason why it worked on an empty database I suppose is a little subtle: the create table statement, by using the fully qualified name to create the table (eg NHibernateDemo.dbo.parkinglot), it doesn't matter what database NHibernate is connecting to. On the other hand the drop statement, by querying sysobjects to determine if the table exists, *is* sensitive to the database at the end of the connection. So, because NHibernate was pointing to the wrong database the wrong sysobjects table was being queried and therefore the table in my test database was not being detected and therefore not dropped.

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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.