How do I customize (JPA) my persistence.xml file if I can customize hibernate.cfg.xml (Hibernate)?

This is what my hibernate.cfg.xml looks like. My program works with this fine. I connected to the MySQL database.

<?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</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.default_schema">mintaalkalmazas2</property> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <property name="hibernate.show_sql">true</property> <mapping resource="Kerdes.hbm.xml"/> <mapping resource="TestTable.hbm.xml"/> </session-factory> </hibernate-configuration> 

This will be persistence.xml . I know that he is not configured yet. I would like to connect to the same MySQL database.

 <?xml version="1.0" encoding="UTF-8" ?> <persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"> <persistence-unit name="todos" transaction-type="RESOURCE_LOCAL"> <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> <class>Todo</class> <properties> <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" /> <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306"></property> <property name="javax.persistence.jdbc.user" value="root" /> <!-- EclipseLink should create the database schema automatically --> <property name="eclipselink.ddl-generation" value="create-tables" /> <property name="eclipselink.ddl-generation.output-mode" value="database" /> </properties> </persistence-unit> </persistence> 

I added these .jar files:

enter image description here

+7
hibernate
source share
2 answers

This one will work:

 <?xml version="1.0" encoding="UTF-8"?> <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0"> <persistence-unit name="myPU" transaction-type="RESOURCE_LOCAL"> <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> <exclude-unlisted-classes>false</exclude-unlisted-classes> <properties> <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/> <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306"/> <property name="javax.persistence.jdbc.user" value="root"/> <property name="javax.persistence.jdbc.password" value="YOUR_PASSWORD"/> <!--Hibernate properties--> <property name="hibernate.show_sql" value="false"/> <property name="hibernate.format_sql" value="false"/> <property name="hibernate.hbm2ddl.auto" value="create"/> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/> </properties> </persistence-unit> </persistence> 

You can put your XML Mappings in an orm.xml file, if you want to have many mapping files, you must attach them using the <mapping-file> element in <persistence-unit> .

You also cannot use mapping files and simply annotate objects.

Update

You must also have Hibernate and its persistence api in the classpath, if you use maven, then you must add the following dependencies:

 <dependency> <groupId>org.hibernate.javax.persistence</groupId> <artifactId>hibernate-jpa-2.1-api</artifactId> <version>1.0.0.Final</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> <version>4.3.5.Final</version> </dependency> 
+4
source share

Why are programmers so stupid bitch? - Why is it so difficult to connect from a Java application to the database? - maybe only these idiots need to be divided into two parts at night on the street?

Fuck off ... I'll be to ** y ** all

-5
source share

All Articles