i deploy oracle database and create 2 schema
- core
- msg
c_user
table is in core and i wanna create m_message
table in msg schema.
my application structure is:
- Core-Project that is a independent dependency and includes in other projects and
User.hbm.xml
is there in it. - i add Core-Project into
pom.xml
of Message-Project. Message-Project hasMessage.hbm.xml
.
i use hibernate 4 and my hibernate mapping file is somethings like below. when i start my application (Message-Project), i wanna to m_message
created foreign key with c_user
table that is in core schema but hibernate generated DDL is wrong. i think hibernate cannot set default_schema properties in User.hbm.xml
that is not schema attribute!
Note. i don't wanna to add a schema attribute in User.hbm.xml
because Core-Project added into more than 10 projects.
Message.hbm.xml in message-project
<class name="org.message.model.Message" table="m_message" schema="msg">
<many-to-one name="sender" column="sender_Id" entity-name="org.core.model.User" not-null="true" />
...
</class>
User.hbm.xml in core-project
<class name="org.core.model.User" table="c_user">
...
</class>
oracle-hibernate.properties
hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver
hibernate.connection.url=jdbc:oracle:thin:@localhost:1521:HRM
hibernate.connection.username=msg
hibernate.connection.password=msg
hibernate.connection.internal_logon=normal
hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
hibernate.hbm2ddl_auto=update
hibernate.default_schema=core
hibernate XML configuration file
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource_" ref="dataSource_" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.default_schema"> ${hibernate.default_schema}</prop>
...
</props>
</property>
</bean>
hibernate generated DDL for foreign key in something like below:
alter table msg.m_message add constraint FK_filpe81gwdf3f6oqn54d5ybh3
foreign key (sender_Id) references msg.c_user
why msg.c_user
? why hibernate cannot set default_schema for tables that haven't schema attribute?
i think the order of using default_schema for generate foreign key is :
- 1) using schema of
User.hbm.xml
and then if not exists - 2) using schema of
Message.hbm.xml
and then if not exists - 3) using the default_schema of oracle-hibernate.properties
how can i change this order? thanks a lot...