-->
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.  [ 9 posts ] 
Author Message
 Post subject: Hibernate SQL as schemaName.tableName failing without owner
PostPosted: Tue Jun 22, 2004 4:06 am 
Senior
Senior

Joined: Fri Jun 18, 2004 10:17 am
Posts: 140
Hi Guys

This is a formulisation of an earlier post on failing insert but more specific...

Basically I have found that Hibernate is sending SQL calls (inserts for example) as schemaName.tableName.

I tried this in SQL Server and it is invalid. SQL Server expects

schemaName.owner.tableName

where owner is pretty much always "dbo".

We've not had this problem before using ouir JDBC JNDI resources since normlly we call connection.setCatalog(schemaName) and calls work after this because JDBC will not prepend statemens with schemaName thereafter.

Is there any way to turn off the prepending of schemaName since this is already set by the JNDI resource anyway. Or is there any other solution?

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 22, 2004 8:14 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Well if you don't specify any schema anywhere, hibernate will not prepend it ...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 22, 2004 8:24 am 
Senior
Senior

Joined: Fri Jun 18, 2004 10:17 am
Posts: 140
OK, I am not telling Hibernate to use a schema. The only place the schema occurs is on the JDBC connection URL. Because I have to tell the connection _somehow_ which schema to use. We have about 15 databases, so Hibernate still has to switch to the right database schema, it can't just issue a straight table call because different schemas may have the same table names.

Like I say, there is not a problem with general connection.setCatalog method in JDBC .. it seems to be that Hibernate is issuing the schema name from the JDBC JNDI connection URL, but if I remove that, Hibernaet will not know _at all_ which schema to use!!

thanks :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 22, 2004 8:34 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Okay, some ideas:

- Hibernate3 will provide not only the possibility to configure the schema, but also the catalog.
- do you need one schema/catalog per SessionFactory? Consider building your own ConnectionProvider which calls setSchema(), setCatalog() before handing out the connection.
- You can still do session.connection().setSchema() ...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 22, 2004 11:50 am 
Senior
Senior

Joined: Fri Jun 18, 2004 10:17 am
Posts: 140
OK well I did the following to solve it ... instead of

Code:
<property name="connection.datasource">java:comp/env/jdbc/schedules</property>


i used

Code:
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.connection.password">blah</property>
<property name="hibernate.connection.url">jdbc:jtds:sqlserver://intratestgbr:1433/dbSchedules;charset=Cp1252;TDS=7.0</property>
<property name="hibernate.connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>   


And the output of Hibernate's calls are now without Schema (but I do session.connection().setCatalog("dbSchedules") in my code.

Hibernate: insert into Schedules (status, title, summary, description, created, last_updated) values (?, ?, ?, ?, ?, ?)
Hibernate: insert into DataAcquisitionSchedules (productName, productRelease, schedule_id) values (?, ?, ?)

I cannot understand why specifying the JNDI datasource causes Hibernate to add the schema onto the sql statements yet using Hibernate's internal connection settings removes it. The settings are identical in their values. Is this intended behaviour?

Cheers, ADC


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 22, 2004 12:16 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
I find that quite hard to believe ... the ConnectionProvider surely does not affect the sql query generation.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 22, 2004 12:17 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
I cannot understand why specifying the JNDI datasource causes Hibernate to add the schema onto the sql statements yet using Hibernate's internal connection settings removes it. The settings are identical in their values. Is this intended behaviour?


No, but I very much doubt it is actual behavior either. I expect you are mistaken.

B.T.W. guys, it is probably possible to do schema="foo.bar" in Hibernate2.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 22, 2004 12:21 pm 
Senior
Senior

Joined: Fri Jun 18, 2004 10:17 am
Posts: 140
I'm not a total novice in these matters, but I appreciate I may be providing you with a red herring certainly.

All I know for sure is :

Using a Tomcat JNDI Resource and telling Hibernate to use the dataSource shows that Hibernate prepends all SQL statements with the schema name. I infer from ths that Hibernate is somehow getting the schema name from the URL connection string itself because I specify is absolutely nowhere else!

I now remove the dataSource method and specify the connection settings for Hibernate instead and still using the very same URL connection string. Hibernate now does not prepend statements with schema name.

These 2 items I have tested and know to be true.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 22, 2004 12:25 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Negative. You are mistaken.


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