Connection error while using Hibernate Logs

Asked

Viewed 105 times

0

I am trying to see the Hibernate generated sqls in my JAVA application but I am having problems because when adding the two commands below are launched some exceptions.

Commands I am inserting into persistence.xml:

  <property name="hibernate.show_sql">true</property> <!-- Show SQL in console -->
  <property name="hibernate.format_sql">true</property> <!-- Show SQL formatted -->

My complete persistence.xml is like this:

<?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="XXXXXX" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <properties>
      <property name="hibernate.connection.username" value="postgres"/>
      <property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
      <property name="hibernate.connection.password" value="root"/>
      <property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/xxxx_new"/>
      <property name="hibernate.connection.autocommit" value="true"/>
      <property name="hibernate.cache.use_query_cache" value="false"/>
      <property name="hibernate.cache.use_second_level_cache" value="false"/>
      <property name="hibernate.hbm2ddl.auto" value="update"/>
      <property name="javax.persistence.sql-load-script-source" value="&lt;property name=&quot;hibernate.show_sql&quot;&gt;true&lt;/property&gt;"/>                         
        <property name="hibernate.show_sql">true</property> <!-- sem essas duas linhs funciona -->
        <property name="hibernate.format_sql">true</property> <!-- sem essas duas linhs funciona -->
    </properties>
  </persistence-unit>
</persistence>

When I add the 2 lines to see the log I have the following Exception:

javax.persistence.PersistenceException: Invalid persistence.xml.
Error parsing XML [line : -1, column : -1] : cvc-complex-type.4: O atributo 'value' deve aparecer no elemento 'property'.
Error parsing XML [line : -1, column : -1] : cvc-complex-type.2.1: O elemento 'property' não deve ter um caractere ou um item com informações do elemento [children] porque o tipo de conteúdo do tipo é vazio.
Error parsing XML [line : -1, column : -1] : cvc-complex-type.4: O atributo 'value' deve aparecer no elemento 'property'.
Error parsing XML [line : -1, column : -1] : cvc-complex-type.2.1: O elemento 'property' não deve ter um caractere ou um item com informações do elemento [children] porque o tipo de conteúdo do tipo é vazio.

1 answer

1


Change the commands to these:

<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />

Using the property value to set value.

  • It worked perfectly thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.