Register   Login   About   Study   Enterprise   Share
Internet / AI Technology University (ITU/AITU)
Fast Login - available after registration







|

Top Links: >> 80. Technology >> Internet Technology Summit Program >> 4. Web Apps Frameworks >> 4.4. Spring with Apache Maven and Data Service Frameworks
Current Topic: 4.4.5. Data Service and JPA/Hibernate frameworks in Maven Project
Sub-Topics: 4.4.5.1. Using JPA/Hibernate
-- Scroll to check for more content below...
You have a privilege to create a quiz (QnA) related to this subject and obtain creativity score...
4.4.5. Data Service and JPA/Hibernate frameworks in Maven Project

Even more benefits brings a combination of Data Service with JPA/Hibernate in a Maven project, which we consider below.

Create a new Maven Project in Eclipse: NEW-Maven Project.

Do not skip the archetype selection (no simple project!).
NEXT
Select the maven-webapp-project archetype for the project.
NEXT
Provide Group ID: com.its
The Group ID should reflect a company/department value.
Provide Artifact ID: 4.4.5.Hibernate
The Artifact ID reflects the project name.
FINISH

A new project with the name 4.4.5.Hibernate appears on the left.
Done! You created a new Maven project with Dynamic Web facilities.

Now, modify (copy/paste) the pom.xml file in the project to include necessary libraries.
Saving the content of the pom.xml file will remove the red spot on the index.jsp file under the webapp directory. The red flag was there because the index.jsp file required the javax.servlet library, which we included in the pom.xml.

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4.0.0
com.pt
4.4.5.Hibernate
war
0.0.1-SNAPSHOT
4.4.5.Hibernate Maven Webapp
http://maven.apache.org


junit
junit
3.8.1
test



javax.mail
mail
1.4.7



org.hibernate
hibernate-core
5.2.2.Final



org.hibernate.javax.persistence
hibernate-jpa-2.1-api
1.0.0.Final



mysql
mysql-connector-java
5.1.6


com.oracle
ojdbc6
11.2.0.3



javax.persistence
persistence-api
1.0.2




javax.servlet
javax.servlet-api
3.1.0





org.apache.maven.plugins
maven-compiler-plugin
2.3.2

1.8
1.8



4.4.5.Hibernate


Was it clear so far?


Right mouse click on the project name and select Properties.
Click on the Project Facets and check the JPA box.
As usually, check on this screen a version of Java and correct if necessary.

There must be a red flag/link Further configuration required.
Click on this link to manage the JPA Facet window.

Select the Platform as Hibernate (JPA 2.1. or higher).
JPA Implementation is provided by a set of libraries, which we included in the pom.xml file.
This allows us to select Disable Library Configuration.
Check if you can also provide Connection to a database.
If not now, you can do this later.
Click OK.

On the right side of the Project Facets screen, click on the Runtime tab and select Tomcat or JBoss server runtime.

After finishing configuration of the Project Facets and adding the JPA features, you can see that the project has a red flag. To see the Problem window go to the Window Menu.

Window - Others - Problem.

The problem, which is related to this new project, is absence of the persistence.xml file.

JPA expects this file to be located in the src/main/resources/META-INF directory.
Create this file manually and copy/paste the following:


xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">


org.hibernate.jpa.HibernatePersistenceProvider
















Assignments:
1. Create a Maven project in Eclipse with the name 4.4.5.Hibernate and follow the description above.
2. Check the following links:
- https://javabrains.io/courses/hibernate_intro/lessons/Introduction-To-Hibernate
- https://www.tutorialspoint.com/hibernate/hibernate_tutorial.pdf
<br/><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<br/>  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 
<br/>  <modelVersion>4.0.0</modelVersion>
<br/>  <groupId>com.pt</groupId>
<br/>  <artifactId>4.4.5.Hibernate</artifactId>
<br/>  <packaging>war</packaging>
<br/>  <version>0.0.1-SNAPSHOT</version>
<br/>  <name>4.4.5.Hibernate Maven Webapp</name>
<br/>  <url>http://maven.apache.org</url>
<br/>  <dependencies>
<br/>    <dependency>
<br/>      <groupId>junit</groupId>
<br/>      <artifactId>junit</artifactId>
<br/>      <version>3.8.1</version>
<br/>      <scope>test</scope>
<br/>    </dependency>
<br/>	<!-- https://mvnrepository.com/artifact/javax.mail/mail -->
<br/>	<dependency>
<br/>		<groupId>javax.mail</groupId>
<br/>		<artifactId>mail</artifactId>
<br/>		<version>1.4.7</version>
<br/>	</dependency>
<br/>  <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<br/>	<dependency>
<br/>	    <groupId>org.hibernate</groupId>
<br/>	    <artifactId>hibernate-core</artifactId>
<br/>	    <version>5.2.2.Final</version>
<br/>	</dependency>
<br/>  <!-- https://mvnrepository.com/artifact/org.hibernate.javax.persistence/hibernate-jpa-2.0-api -->
<br/><dependency>
<br/>    <groupId>org.hibernate.javax.persistence</groupId>
<br/>    <artifactId>hibernate-jpa-2.1-api</artifactId>
<br/>    <version>1.0.0.Final</version>
<br/></dependency>
<br/><!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<br/><dependency>
<br/>    <groupId>mysql</groupId>
<br/>    <artifactId>mysql-connector-java</artifactId>
<br/>    <version>5.1.6</version>
<br/></dependency>
<br/><dependency>
<br/>    <groupId>com.oracle</groupId>
<br/>    <artifactId>ojdbc6</artifactId>
<br/>    <version>11.2.0.3</version>
<br/></dependency>
<br/>  <!-- https://mvnrepository.com/artifact/javax.persistence/persistence-api -->
<br/><dependency>
<br/>    <groupId>javax.persistence</groupId>
<br/>    <artifactId>persistence-api</artifactId>
<br/>    <version>1.0.2</version>
<br/></dependency>
<br/>
<br/>
<br/> <dependency>
<br/>    <groupId>javax.servlet</groupId>
<br/>    <artifactId>javax.servlet-api</artifactId>
<br/>    <version>3.1.0</version>
<br/>   </dependency>    
<br/>  </dependencies>
<br/>	<build>
<br/>		<plugins>
<br/>			<plugin>
<br/>				<groupId>org.apache.maven.plugins</groupId>
<br/>				<artifactId>maven-compiler-plugin</artifactId>
<br/>				<version>2.3.2</version>
<br/>				<configuration>
<br/>					<source>1.8</source>
<br/>					<target>1.8</target>
<br/>				</configuration>
<br/>			</plugin>
<br/>		</plugins>
<br/>		<finalName>4.4.5.Hibernate</finalName>
<br/>	</build>
<br/></project> 
<br/>






Was it clear so far?



Right mouse click on the project name and select Properties.
Click on the Project Facets and check the JPA box.
As usually, check on this screen a version of Java and correct if necessary.

There must be a red flag/link Further configuration required.
Click on this link to manage the JPA Facet window.

Select the Platform as Hibernate (JPA 2.1. or higher).
JPA Implementation is provided by a set of libraries, which we included in the pom.xml file.
This allows us to select Disable Library Configuration.
Check if you can also provide Connection to a database.
If not now, you can do this later.
Click OK.

On the right side of the Project Facets screen, click on the Runtime tab and select Tomcat or JBoss server runtime.

After finishing configuration of the Project Facets and adding the JPA features, you can see that the project has a red flag. To see the Problem window go to the Window Menu.

Window - Others - Problem.

The problem, which is related to this new project, is absence of the persistence.xml file.

JPA expects this file to be located in the src/main/resources/META-INF directory.
Create this file manually and copy/paste the following:

<br/><persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<br/>  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
<br/>http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
<br/>  version="2.1">
<br/> 
<br/>  <persistence-unit name="sampledb" transaction-type="RESOURCE_LOCAL">
<br/>   <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<br/>  
<br/>   <properties>
<br/>    <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/sampledb?user=sampledb" />
<br/>    <property name="javax.persistence.jdbc.user" value="sampledb" />
<br/>    <property name="javax.persistence.jdbc.password" value="psw" />
<br/>    <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<br/>    <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<br/>    <property name="hibernate.show_sql" value="true" />
<br/>    <property name="hibernate.format_sql" value="true" />
<br/>
<br/>    <!-- Configuring Connection Pool (optional) -->
<br/>    </properties>
<br/>  </persistence-unit>      
<br/></persistence>
<br/>


Assignments:
1. Create a Maven project in Eclipse with the name 4.4.5.Hibernate and follow the description above.
2. Check the following links:
- https://javabrains.io/courses/hibernate_intro/lessons/Introduction-To-Hibernate
- https://www.tutorialspoint.com/hibernate/hibernate_tutorial.pdf


Have a suggestion? - shoot an email
Looking for something special? - Talk to me
Read: IT of the future: AI and Semantic Cloud Architecture | Fixing Education
Do you want to move from theory to practice and become a magician? Learn and work with us at Internet Technology University (ITU) - JavaSchool.com.

Technology that we offer and How this works: English | Spanish | Russian | French

Internet Technology University | JavaSchool.com | Copyrights © Since 1997 | All Rights Reserved
Patents: US10956676, US7032006, US7774751, US7966093, US8051026, US8863234
Including conversational semantic decision support systems (CSDS) and bringing us closer to The message from 2040
Privacy Policy