Skip to content

Instantly share code, notes, and snippets.

@seycileli
Last active January 13, 2020 21:31
Show Gist options
  • Save seycileli/4b40447d1fb63cdf929e156a34028538 to your computer and use it in GitHub Desktop.
Save seycileli/4b40447d1fb63cdf929e156a34028538 to your computer and use it in GitHub Desktop.
Main way to write and always use a persistence.xml file and connecting to a database
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="any-name-you-want-here">
<!-- The persistence-unit name can be whatever you like -->
<!-- This is the BRAIN of our project -->
<!-- ADD (CLASSES) ENTITIES /OR MODELS CREATED FOR BY ME FOR MY APP -->
<!-- here you include every class/ entity - as shown in the example below -->
<!-- com.projectname.entities.classname above -->
<!-- class only has to do with database, only add packages related to it -->
<class>com.projectname.entities.classnamehere</class>
<!-- ADD PROPERTIES BELOW -->
<!-- database connectivity -->
<properties>
<property name="javax.persistence.jdbc.url"
value="jdbc:mariadb://localhost:3306/db-name-here?useSSL=false" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="" />
<property name="javax.persistence.jdbc.driver"
value="org.mariadb.jdbc.Driver" />
<property name="eclipselink.ddl-generation"
value="create-tables" />
<property name="eclipselink.target-database" value="MYSQL" />
<property name="eclipselink.logging.level" value="FINE" />
</properties>
</persistence-unit>
</persistence>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment