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