From the course: Java Persistence API (JPA): 1 The Basics
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
JPA configuration and entities - Java Tutorial
From the course: Java Persistence API (JPA): 1 The Basics
JPA configuration and entities
- [Instructor] There are two ways to define JPA metadata. The most common way is to define it via annotations in the Java class. Alternatively, the metadata can be defined via XML, or a combination of both. The chosen method for this course is annotations. An important tip to note is that if you use the XML configuration file, it will overwrite any annotations you've provided. Starting with Spring 3.1, the persistence XML is no longer necessary because Spring can scan all packages looking for entities described by the @Entity annotation. JPA can be fully setup with no XML which is very convenient. I mentioned that Spring scans looking for entities, but what is an entity? Entities are objects that live in a database and have the ability to be mapped to a database. Entities are defined by the @Entity annotation. Entities support inheritance, relationships, etc., they also have a unique identifier. This example code represents a simple entity- an object with attributes, constructors…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.