1

I'm currently trying to get hibernate to send my Java EE Entities in my postgresql database using an EJB. My entity code (for testing, I use the simplest one) is :


import java.io.Serializable;

@Entity

public class Coup implements Serializable {

    private static final long serialVersionUID = 1L;

    @Column(unique=true, nullable=false)
    @Id
    private String name;

    @Column(nullable=false)
    private String jeu;

    public Coup() {
    }

    public Coup(String name, String jeu) {
        this.name = name;
        this.jeu = jeu;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getJeu() {
        return this.jeu;
    }

    public void setJeu(String jeu) {
        this.jeu = jeu;
    }

}

and my hibernate.xml file is

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/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_1_0.xsd">
  <persistence-unit name="PostgresDSjeeux" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>java:/PostgresDSjeeux</jta-data-source>
    <class>Equipe</class>
    <class>Joueur</class>
    <class>Salon</class>
    <class>Partie</class>
    <class>HautFait</class>
    <class>Coup</class>
    <properties>

    <!-- <property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>  -->  
      <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
      <property name="hibernate.show_sql" value="true" />
    <!-- <property name="transaction.factory_class" value="org.hibernate.transaction.JDBCTransactionFactory" /> --> 

    </properties>
  </persistence-unit>
</persistence>

However, after I execute this

            Coup c = new Coup();
            c.setJeu("superjeu");
            c.setName("supername");
                em.persist(c);

code, the generated query that I see in the JBOSS6 log is :

14:57:59,364 INFO  [STDOUT] Hibernate: insert into Coup (jeu, name) values (?, ?)

Thanks for any answer you might provide.

1 Answer 1

3

I think that's just a logging message from the PreparedStatement to show the bound parameters.

Did you look in the database to see what was INSERTed? That's the only thing that matters, not the log.

Sign up to request clarification or add additional context in comments.

3 Comments

God I really feel so dumb. Sorry for asking this question, the data was since the beginning in the database, but I thought it just didn't work. I just installed pgadmin3, all my data is there... Thanks a lot :)
If you want to see the actual values in a log file, you have to use a tool like log4jdbc
That's not exactly true. You can ask Hibernate to log the values it is binding to those PreparedStatement parameters using the org.hibernate.type logger (on 3.x) or org.hibernate.type.descriptor.sql logger (on 4.x) set to TRACE. If you want the logging to show the statement and parameters together (i.e., insert into Coup (jeu, name) values (1, 'abc')), then yes you will need another means like log4jdbc or logging jdbc wrappers. The benefit of having Hibernate log this is you can see both ways: binding to PreparedStatements and extracting from ResultSets

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.