简体   繁体   中英

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

        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">
<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;

}

您将永远不会看到插入到数据库中的字符串的值,您将始终将它们视为问号(?),其中有嗅探器将显示其内容,但是在标准休眠模式下,您将看不到任何值。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM