views:

107

answers:

1

Hello, I was doing simple things with hibernate, as I have to learn it for a project. I created this simple example:

package hibtests;

import hibtests.beans.newBean;
import org.hibernate.Session;

/**
 *
 * @author dario
 */
public class Main {


    public void test(){
        Session session = NewHibernateUtil.getSessionFactory().getCurrentSession();

        session.beginTransaction();

        newBean nb = new newBean();
        nb.setNome("FooFoo");
        session.save(nb);

        session.getTransaction().commit();

    }
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here

        Main main = new Main();
        main.test();
    }

}

...and it was working fine, putting rows in the db. Then I worked on another class for a couple of hours. I try this example again and Hibernate makes this strange query:

Hibernate: 
    insert 
    into
        TEST
        (ID, NOME) 
    values
        (default, ?)
Hibernate: 

values
    identity_val_local()

like it just can't read the property that is FooFoo. I checked if I changed the source... but it is not the case. Everything is just like before and there are not exceptions. The newBean instance is not null and FooFoo is in the Nome field. Why this?

Oh, I forgot, I'm using Netbeans 6.8 and JavaDB.

As requested, my mapping follows:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"&gt;
<hibernate-mapping>
    <class name="hibtests.beans.newBean" table="APP.TEST">
        <id name="id" column="ID">
           <generator class="identity"/>
        </id>
        <property name="nome" column="NOME" type="string"/>
    </class>
</hibernate-mapping>

Last minute update: turns out that insertion is working. Anyway I can still see the query with a ? instead of the string. Why?


As requested newbean source code follows:

public class newBean {

Long id;

public Long getId() {
    return id;
}

public void setId(Long id) {
    this.id = id;
}

public String getNome() {
    return nome;
}

public void setNome(String nome) {
    this.nome = nome;
}
String nome;

}

+1  A: 

You will never see the value of the strings being inserted in the DB, you will always see them as question marks (?) there are sniffers that will show their contents, but in standard hibernate you will not see any values.

Omar Al Kababji
Exactly... the ?s are parameter markers... thats the expected behaviour.
jsight