![]() |
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 NetSuite to generate an ORM of your NetSuite repository with Hibernate.
Though Eclipse is the IDE of choice for this article, the CData JDBC Driver for NetSuite works in any product that supports the Java Runtime Environment. In the Knowledge Base you will find tutorials to connect to NetSuite data from IntelliJ IDEA and NetBeans.
CData provides the easiest way to access and integrate live data from Oracle NetSuite. Customers use CData connectivity to:
Customers use CData solutions to access live NetSuite data from their preferred analytics tools, Power BI and Excel. They also use CData's solutions to integrate their NetSuite data into comprehensive databases and data warehouse using CData Sync directly or leveraging CData's compatibility with other applications like Azure Data Factory. CData also helps Oracle NetSuite customers easily write apps that can pull data from and push data to NetSuite, allowing organizations to integrate data from other sources with NetSuite.
For more information about our Oracle NetSuite solutions, read our blog: Drivers in Focus Part 2: Replicating and Consolidating ... NetSuite Accounting Data.
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 NetSuite data.
Input the following values:
Connection URL: A JDBC URL, starting with jdbc:netsuite: and followed by a semicolon-separated list of connection properties.
The User and Password properties, under the Authentication section, must be set to valid NetSuite user credentials. In addition, the AccountId must be set to the ID of a company account that can be used by the specified User. The RoleId can be optionally specified to log in the user with limited permissions.
See the "Getting Started" chapter of the help documentation for more information on connecting to NetSuite.
For assistance in constructing the JDBC URL, use the connection string designer built into the NetSuite JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.
java -jar cdata.jdbc.netsuite.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:netsuite:Account Id=XABC123456;Password=password;User=user;Role Id=3;Version=2013_1;
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 NetSuite 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.netsuite.NetSuiteDriver jdbc:netsuite:Account Id=XABC123456;Password=password;User=user;Role Id=3;Version=2013_1; org.hibernate.dialect.SQLServerDialect
Using the entity you created from the last step, you can now search and modify NetSuite 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 SalesOrder S WHERE Class_Name = :Class_Name";
Query q = session.createQuery(SELECT, SalesOrder.class);
q.setParameter("Class_Name","Furniture : Office");
List<SalesOrder> resultList = (List<SalesOrder>) q.list();
for(SalesOrder s: resultList){
System.out.println(s.getCustomerName());
System.out.println(s.getSalesOrderTotal());
}
}
}
Download a free trial of the NetSuite Driver to get started:
Download NowLearn more:
๐ NetSuite IconRapidly create and deploy powerful Java applications that integrate with NetSuite account data including Leads, Contacts, Opportunities, Accounts, and more!