-->
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: hibernate.hbm2ddl.auto=validate with entities mapping views
PostPosted: Thu Nov 29, 2007 9:22 am 
Newbie

Joined: Thu Nov 29, 2007 8:53 am
Posts: 1
Hi!

I'm having an entity called 'Personal' which is mapped to a database view in the given schema in my postgresql database with the following annotation:

Code:
@Entity
@Table(name = "view_user", schema="user_management")
public class Personal implements Serializable{
...
}


If persistemce.xml is setting 'hbm2ddl.auto' to 'update', I'm getting a warning in jboss.log because hibernate wants to create a table with the given name, which cannot be done, because a view with the same name already exists.

Quote:
INFO [org.hibernate.tool.hbm2ddl.DatabaseMetadata] table not found: view_user
INFO [org.hibernate.tool.hbm2ddl.DatabaseMetadata] table not found: view_user
ERROR [org.hibernate.tool.hbm2ddl.SchemaUpdate] Unsuccessful: create table user_management.view_user (id int8 not null, account_name varchar(25) not null, ... , primary key (id))
ERROR [org.hibernate.tool.hbm2ddl.SchemaUpdate] ERROR: relation "view_user" already exists


Actually this could be safely ignored, since after all, everything is working as expected throughout my application (there are insert, update and delete rules on the view) and all persistence operations are handled using the view.

In a production environment, I wouldn't like my application server to update my database at startup so I would like to disable the DDL process.

If I change my persistemce.xml reflecting 'hbm2ddl.auto' set to 'validate', deployment fails with the following log entry:
Quote:
2007-11-29 14:15:06,228 INFO [org.hibernate.tool.hbm2ddl.DatabaseMetadata] table not found: view_user
2007-11-29 14:15:06,228 WARN [org.jboss.system.ServiceController] Problem starting service persistence.units:ear=umgmt.ear,jar=umgmt.jar,unitName=umgmt
javax.persistence.PersistenceException: org.hibernate.HibernateException: Missing table: view_user

Understandable, if one thinks about it, because hibernate doesn't find a table with the given name, because its a view.

So finally I'm asking myself the following questions:
1) Is there a way to tell hibernate, that the given relationship is a view and not a table and hence be detected by hbm2ddl?
2) Is there a way to skip the validation of the schema at all (hbm2ddl.auto=NONE) and relying on the fact, that all views/tables are in place already
3) Is my mapping to a view done correctly?

Any help or pointers are greatly appreciated, I'm banging my head for quite a while now ;)

By the way, I'm using postgresql 8.2.5 with postgresql-8.2-506.jdbc3.jar as the JDBC connector.

Best regards, Kurt


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 21, 2007 12:10 pm 
Newbie

Joined: Fri Dec 21, 2007 12:09 pm
Posts: 3
Hey, happen to be bumping in to the same thing right now. If I find a solution, I'll post it here.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 21, 2007 12:18 pm 
Newbie

Joined: Fri Dec 21, 2007 12:09 pm
Posts: 3
Several reports are already in JIRA about this: HHH-2018, HHH-1872, and (more extensively) HHH-1329. The easiest workaround for now is to turn hbm2ddl off.
Seems to happen with Postgres, Oracle, and likely with other databases as well.


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