Step-1: Install Hibernate support plugin
Step-2: Create maven project of archetype-webapp
Create a new project from New -> Project -> Maven -> archetype -> webapp
Step-3: Hibernate config
Create the below config and save it as hibernate-cfg.xml
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password">root</property> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <property name="hibernate.default_schema">test</property> </session-factory> </hibernate-configuration>
Also include mysql connector in your POM,
<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.17</version> </dependency>
Step-4: Create POJOs using the Plugin
You can navigate to the plugin from view -> tool windows -> persistence
as shown below, here mockbook
is the name of a sample application.
Error creating pojos
The plugin will have issues if JDK is not installed properly, make sure that SDK is properly set. You can do it from the warning header as shown below or by navigating to the project structure.