DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Fixing Common Oracle Database Problems
  • Copy SQL Execution Plan from One Database to Another in Oracle 19c
  • Exploring the New Boolean Data Type in Oracle 23c AI
  • Implement Hibernate Second-Level Cache With NCache

Trending

  • Rust, WASM, and Edge: Next-Level Performance
  • Enforcing Architecture With ArchUnit in Java
  • Monolith: The Good, The Bad and The Ugly
  • Event-Driven Microservices: How Kafka and RabbitMQ Power Scalable Systems
  1. DZone
  2. Data Engineering
  3. Databases
  4. Oracle Database Link and Hibernate Mapping

Oracle Database Link and Hibernate Mapping

The article is to describe how to create a Database link in Oracle and use Hibernate to create mapping for the remote table.

By 
Eason YIN user avatar
Eason YIN
·
Oct. 06, 20 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
6.8K Views

Join the DZone community and get the full member experience.

Join For Free

The article is to describe how to create a Database link in Oracle and use Hibernate to create mapping for the remote table.

Grant Privilege

Grant create/drop database link privilege to a user, and we also need the grant to create view privilege for the user

Run below SQL by SYSDBA

SQL> GRANT CREATE PUBLIC DATABASE LINK TO <USER>;

SQL> GRANT DROP PUBLIC DATABASE LINK TO <USER>;

SQL> GRANT CREATE VIEW TO <USER>;

Database Link

Login and run below SQL to create a database link 

Java
 




x


 
1
CREATE <PUBLIC> DATABASE LINK <DB_LINK> CONNECT TO <DATABASE_USER> IDENTIFIED BY <DATABASE_PASSWORD> USING '(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = <DATABASE HOSTNAME>)(PORT = <PORT>)))(CONNECT_DATA = (SERVICE_NAME = <SERVICE NAME>)))';



Attached Oracle document:   https://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_5005.htm

Description of create_database_link.gif follows

Viewing Information About Database Links

Java
 




xxxxxxxxxx
1


 
1
SELECT * FROM DBA_DB_LINKS  #Lists all database links in the database.
2

          
3
SELECT * FROM ALL_DB_LINKS #Lists all database links accessible to the connected user.
4

          
5
SELECT * FROM USER_DB_LINKS  #Lists all database links owned by the connected user.



Delete Database Link

DROP <PUBLIC> DATABASE LINK <DB_LINK>;

View

Create View to map remote database table

CREATE VIEW <VIEW> AS (SELECT * FROM <REMOTE TABLE>@<DB_LINK>;

Hibernate Mapping

We can use a common way to create hibernate mapping to a Database View. For example

<hibernate-mapping>
<class name="com.xx.xxx.xxxx.hibernate.entity.view.XXXX"
table="<VIEW>" dynamic-update="true">
...
</class>
</hibernate-mapping>

SYNONYM

We also can create a synonym table instead of view after the Database link created

CREATE PUBLIC SYNONYM <SYNONYM>  FOR  <REMOTE TABLE>@<DB_LINK>;

Hibernate Mapping

We can map a synonym table like below

Java
 




xxxxxxxxxx
1


 
1
<hibernate-mapping>
2
    <class name="com.xx.xxx.xxx.hibernate.entity.view.XXXX"
3
           table="<Remote Table>@<DB_LINK>" dynamic-update="true">
4
           ...
5
    </class>
6
</hibernate-mapping>



Furthermore,  hibernate configuration need below changes

<!-- Add below one -->
<prop key="hibernate.synonyms">true</prop>

And hibernate need disable auto validation.

<!-- Remove below one -->
<!--prop key="hibernate.hbm2ddl.auto">validate</prop-->

Database Links Hibernate Oracle Database

Opinions expressed by DZone contributors are their own.

Related

  • Fixing Common Oracle Database Problems
  • Copy SQL Execution Plan from One Database to Another in Oracle 19c
  • Exploring the New Boolean Data Type in Oracle 23c AI
  • Implement Hibernate Second-Level Cache With NCache

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!