![]() |
VOOZH | about |
You can use Hibernate to map object-oriented domain models to a traditional relational database. The tutorial below shows how to use the CData JDBC Driver for Dynamics 365 to generate an ORM of your Dynamics 365 repository with Hibernate.
Though Eclipse is the IDE of choice for this article, the CData JDBC Driver for Dynamics 365 works in any product that supports the Java Runtime Environment. In the Knowledge Base you will find tutorials to connect to Dynamics 365 data from IntelliJ IDEA and NetBeans.
CData simplifies access and integration of live Microsoft Dynamics 365 data. Our customers leverage CData connectivity to:
CData customers use our Dynamics 365 connectivity solutions for a variety of reasons, whether they're looking to replicate their data into a data warehouse (alongside other data sources) or analyze live Dynamics 365 data from their preferred data tools inside the Microsoft ecosystem (Power BI, Excel, etc.) or with external tools (Tableau, Looker, etc.).
Follow the steps below to install the Hibernate plug-in in Eclipse.
Follow the steps below to add the driver JARs in a new project.
Follow the steps below to configure connection properties to Dynamics 365 data.
Input the following values:
Connection URL: A JDBC URL, starting with jdbc:dynamics365: and followed by a semicolon-separated list of connection properties.
Edition and OrganizationUrl are required connection properties. The Dynamics 365 connector supports connecting to the following editions: CustomerService, FieldService, FinOpsOnline, FinOpsOnPremise, HumanResources, Marketing, ProjectOperations and Sales.
For Dynamics 365 Business Central, use the separate Dynamics 365 Business Central driver.
OrganizationUrl is the URL to your Dynamics 365 organization. For instance, https://orgcb42e1d0.crm.dynamics.com
For assistance in constructing the JDBC URL, use the connection string designer built into the Dynamics 365 JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.
java -jar cdata.jdbc.dynamics365.jar
Fill in the connection properties and copy the connection string to the clipboard.
๐ Using the built-in connection string designer to generate a JDBC URL (Salesforce is shown.)A typical JDBC URL is below:
jdbc:dynamics365:OrganizationUrl=https://myaccount.operations.dynamics.com/;Edition=Sales;InitiateOAuth=GETANDREFRESH;
Follow the steps below to select the configuration you created in the previous step.
Follow the steps below to generate the reveng.xml configuration file. You will specify the tables you want to access as objects.
Follow the steps below to generate plain old Java objects (POJO) for the Dynamics 365 tables.
One or more POJOs are created based on the reverse-engineering setting in the previous step.
For each mapping you have generated, you will need to create a mapping tag in hibernate.cfg.xml to point Hibernate to your mapping resource. Open hibernate.cfg.xml and insert the mapping tags as so:
cdata.dynamics365.Dynamics365Driver jdbc:dynamics365:OrganizationUrl=https://myaccount.operations.dynamics.com/;Edition=Sales;InitiateOAuth=GETANDREFRESH; org.hibernate.dialect.SQLServerDialect
Using the entity you created from the last step, you can now search and modify Dynamics 365 data:
import java.util.*;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
import org.hibernate.query.Query;
public class App {
public static void main(final String[] args) {
Session session = new
Configuration().configure().buildSessionFactory().openSession();
String SELECT = "FROM GoalHeadings G WHERE Name = :Name";
Query q = session.createQuery(SELECT, GoalHeadings.class);
q.setParameter("Name","MyAccount");
List<GoalHeadings> resultList = (List<GoalHeadings>) q.list();
for(GoalHeadings s: resultList){
System.out.println(s.getGoalHeadingId());
System.out.println(s.getName());
}
}
}
Download a free trial of the Dynamics 365 Driver to get started:
Download NowLearn more:
๐ Dynamics 365 IconRapidly create and deploy powerful Java applications that integrate with Dynamics 365.