-->
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.  [ 10 posts ] 
Author Message
 Post subject: HSQLDB+Spring+hbm2ddl = schema creation issues
PostPosted: Mon Jan 22, 2007 10:52 am 
Newbie

Joined: Mon Jan 22, 2007 10:40 am
Posts: 3
Hi all,

I working on a project that using Hibernate for DAOs (in conjunction with Spring). For our unit testing, our underlying DB2 database is being swapped for an in-memory instance of HSQLDB, by injecting a new datasource into to client code using Spring.

The problem is due to Hibernates auto creation of schemas; the hbm files look like:
Code:
<class name="xyzclass" table="xyztable">


Inside of the Session Factory bean, we are setting
Code:
hibernate.hbm2ddl.auto=create-drop
to dynamically create the tables (as the database is in-memory and is setup each time the JVM runs) such that the DAOs are able to use the DB without any additional configuration. However, this tries to create a table similar to the example above using SQL such as:

Code:
create table SCHEMA.TABLE (TRANSACTION_REFE…


This fails as the schema is not defined:

Code:
invalid schema name: SCHEMA in statement [create table SCHEMA.TABLE]


This has been discussed a few times, but without any resolution, esp. when using Spring. So far I can't find a solution without having my jUnit code manually create the schema (which defeats the point of using hbm2dll as the schema will only be created after this has already run), and forcing the Spring controlled beans to be lazily instantiated to control them from being loaded prior to any manual SQL being run.
Has anyone had prior experience of this, and any advice on how to overcome this problem? We're using Hibernate 3.2.1.ga.

Best regards,
-James


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 26, 2007 8:07 am 
Newbie

Joined: Fri Jan 26, 2007 8:06 am
Posts: 1
Location: Brazil
SCHEMA is a reserved word? =)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 26, 2007 9:22 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you apparently have set hibernate.default_schema to some schema name that does not exist.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 29, 2007 7:06 am 
Newbie

Joined: Mon Jan 22, 2007 10:40 am
Posts: 3
dominoni wrote:
SCHEMA is a reserved word? =)


I was using SCHEMA as an example...

max wrote:
you apparently have set hibernate.default_schema to some schema name that does not exist.


This works for RDBMS's that support implicit schema creation, but not for ones that don't, i.e. HSQLDB.

I still don't think there is a workaround for this issue!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 29, 2007 7:39 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
hibernate *only* put schema in their IIF schema attribute is set OR if hibernate.default_schema is set.

So if you really have a schema in your database make sure it is available for hibernate to create stuff in...it's that simple.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 29, 2007 7:44 am 
Newbie

Joined: Mon Jan 22, 2007 10:40 am
Posts: 3
max wrote:
hibernate *only* put schema in their IIF schema attribute is set OR if hibernate.default_schema is set.

So if you really have a schema in your database make sure it is available for hibernate to create stuff in...it's that simple.


Thanks for your reply Max. Do you think that this could be a candidate feature for future versions of Hibernate?
When doing unit testing using an in-memory, in-process DB instance, its requires that the DB is initialized (i.e. schemas created) prior to Hibernate trying to create any tables that don't exist. I don't think this is possible as Hibernate fires off as soon as the JVM starts without having some sort of hook to act as a pre-processor to the Hib mapping process.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 29, 2007 7:53 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Hibernate does not fire off before you tell it to. Do the adjustments to the underlying database before you do that.

and yes there an issue for making this a more integrated part of schemaexport/update at some point...but until now noone have supplied a workable patch.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 23, 2007 12:36 pm 
Beginner
Beginner

Joined: Thu Apr 29, 2004 4:31 am
Posts: 42
hi all,
has anyone found a workaround to this? i am stuck in the same situation using in-memory database and a schema.......

thanks in advance and regards
marco


Top
 Profile  
 
 Post subject: Same problem
PostPosted: Wed Oct 24, 2007 2:45 pm 
Newbie

Joined: Wed Oct 24, 2007 2:39 pm
Posts: 7
Hi all.
I had the same problem.
My mappings have different schemas. Anybody has some solution ?
I'm using the HSQLDB that don't have implicit schema creation, in the same architecture that JHarvey :(

JHarvey, how do you do ?

thanks


Top
 Profile  
 
 Post subject: Same problem
PostPosted: Wed Oct 24, 2007 2:46 pm 
Newbie

Joined: Wed Oct 24, 2007 2:39 pm
Posts: 7
Hi all.
I had the same problem.
My mappings have different schemas. Somebody has some solution ?
I'm using the HSQLDB that don't have implicit schema creation, in the same architecture that JHarvey :(

JHarvey, how do you do ?

thanks


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