![]() |
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 SharePoint to generate an ORM of your SharePoint repository with Hibernate.
Though Eclipse is the IDE of choice for this article, the CData JDBC Driver for SharePoint works in any product that supports the Java Runtime Environment. In the Knowledge Base you will find tutorials to connect to SharePoint data from IntelliJ IDEA and NetBeans.
Accessing and integrating live data from SharePoint has never been easier with CData. Customers rely on CData connectivity to:
Most customers rely on CData solutions to integrate SharePoint data into their database or data warehouse, while others integrate their SharePoint data with preferred data tools, like Power BI, Tableau, or Excel.
For more information on how customers are solving problems with CData's SharePoint solutions, refer to our blog: Drivers in Focus: Collaboration Tools.
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 SharePoint data.
Input the following values:
Connection URL: A JDBC URL, starting with jdbc:sharepoint: and followed by a semicolon-separated list of connection properties.
Set the URL property to the base SharePoint site or to a sub-site. This allows you to query any lists and other SharePoint entities defined for the site or sub-site.
The User and Password properties, under the Authentication section, must be set to valid SharePoint user credentials when using SharePoint On-Premise.
If you are connecting to SharePoint Online, set the SharePointEdition to SHAREPOINTONLINE along with the User and Password connection string properties. For more details on connecting to SharePoint Online, see the "Getting Started" chapter of the help documentation
For assistance in constructing the JDBC URL, use the connection string designer built into the SharePoint JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.
java -jar cdata.jdbc.sharepoint.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:sharepoint:User=myuseraccount;Password=mypassword;Auth Scheme=NTLM;URL=http://sharepointserver/mysite;SharePointEdition=SharePointOnPremise;
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 SharePoint 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.sharepoint.SharePointDriver jdbc:sharepoint:User=myuseraccount;Password=mypassword;Auth Scheme=NTLM;URL=http://sharepointserver/mysite;SharePointEdition=SharePointOnPremise; org.hibernate.dialect.SQLServerDialect
Using the entity you created from the last step, you can now search and modify SharePoint 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 MyCustomList M WHERE Location = :Location";
Query q = session.createQuery(SELECT, MyCustomList.class);
q.setParameter("Location","Chapel Hill");
List<MyCustomList> resultList = (List<MyCustomList>) q.list();
for(MyCustomList s: resultList){
System.out.println(s.getName());
System.out.println(s.getRevenue());
}
}
}
Download a free trial of the SharePoint Driver to get started:
Download NowLearn more:
๐ SharePoint IconProvides Java developers with the power to easily connect their Web, Desktop, and Mobile applications to data in SharePoint Server Lists, Contacts, Calendar, Links, Tasks, and more!