开发者

Hibernate doesn't work anymore... why?

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

        Ma开发者_运维百科in 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">
<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;

}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜