Here's my problem:
1 - I'm using the Postgre 9.6 database.
2 - I downloaded and opened in ECLIPSE a project with Java application example with the use of Hibernate and Postgre that the teacher created (that is, the code is correct) I put the Postgre JDBC driver jar, version: 4.2.0.0 in Eclipse on the "Java Build Path".
3 - The version of Jdk that is installed and linked to Eclipse is 1.7.0_80 which I thought would be compatible with Postgre and the above JDBC driver.
The error: When running the application, Eclipse has errors:
Exception in thread "main" java.lang.UnsupportedClassVersionError: br/com/bd2/teste/TesteDatabase : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
And the JVM opens an alert window with this message: "A Java Exception has ocurred!"
Below are the prints:
EclipseErrors:Theprojectinquestionisthe"Hibernate Example":
Andthisisthecodeformymainclass:
packagebr.com.bd2.teste;importjavax.persistence.EntityManager;importjavax.persistence.EntityManagerFactory;importjavax.persistence.Persistence;importjavax.persistence.TypedQuery;importbr.com.bd2.exemplo.model.Fruteira;publicclassTesteDatabase{publicstaticvoidmain(String[]args){//Inicializacaodafabricadeobjetos//persistenceUnitName="bd2", ou seja, relaciona com a conexao na
// persistence.xml (podera ter "n" unidades de persistencia)
EntityManagerFactory emf = Persistence.createEntityManagerFactory("bd2_persistence_unit");
EntityManager em = emf.createEntityManager();
// Os comandos a seguir devem ser executados "um por vez"
// Inserindo...
em.getTransaction().begin();
em.persist(new Fruteira("Fruteira"));
em.persist(new Fruteira("Fruteira 3"));
em.getTransaction().commit();
// Atualizando...
// Buscara a fruteira com id = 1. Observe o numero do id pelo pgAdmin3!
Fruteira fruteira = em.find(Fruteira.class, 1L);
if (fruteira != null) {
em.getTransaction().begin();
fruteira.setNome("Fruteira Legal");
em.merge(fruteira);
em.getTransaction().commit();
}
// Recuperando "n" objetos...
TypedQuery<Fruteira> q = em.createQuery("SELECT f " +
"FROM Fruteira f", Fruteira.class);
for (Fruteira each : q.getResultList()) {
System.out.println(each.toString());
}
// Excluindo...
// Buscara a fruteira com id = 1. Observe o numero do id pelo pgAdmin3!
fruteira = em.find(Fruteira.class, 1L);
if (fruteira != null) {
em.getTransaction().begin();
em.remove(fruteira);
em.getTransaction().commit();
}
// Recuperando "n" objetos...
q = em.createQuery("FROM Fruteira f", Fruteira.class);
for (Fruteira each : q.getResultList()) {
System.out.println(each.toString());
}
System.exit(0);
}