views:

30

answers:

2

Is there a way to tell hibernate's hbm2ddl to not create specific table but still have the model be recognized by Hibernate.

The thing is that the model map to a view and I want to have an in-memory database (empty on startup and deleted on termination) for testing, hence, having 2 sets of mapping is out of the question.

A: 

Is there a way to tell hibernate's hbm2ddl to not create specific table

AFAIK, hbm2ddl is "all or nothing", you can't exclude specific tables. But you could use it to output the generated DDL to a file instead of automatically exporting it to the database if you want to alter the DDL. Would this help?

but still have the model be recognized by Hibernate.

I didn't get that part. Do you mean having Hibernate validate the database against the mapping?

Pascal Thivent
I meant that I can query that table using hibernate, not through a separate system.
RichN
+1  A: 

Okay, this doesn't exactly answer the question (there's probably no way to do it with current version) but it does solve the issue at hand.

So, in the end I let hibernate create the table but later on forcefully drop it and put in my own create view statement. It seems that there are 2 ways to do it.

The first way is by using the <database-object> element, specifically the child element called <create>, like so:

<class table="MY_VIEW"></class>
<database-object>
  <create>
    drop table MY_VIEW;
    create view MY_VIEW etc etc;
  </create>
</database-object>

The other way is by entering the same thing in the import.sql. This thing is undocumented. I don't know why, perhaps it's deprecated. I assume it is so, hence I won't put too much detail here. It's not deprecated, but I find the previous method less painful (the create view is several lines long).

RichN
The import.sql is not deprecated, it's just not documented.
Pascal Thivent
@Pascal Noted. After searching more through Google and source codes, I can see now that it should have been perfectly clear if I were using the SchemaExport class. Alas, I've never touched it directly before.
RichN
Use the sources, luke :) +1 for the hack anyway.
Pascal Thivent