My real code using java 6, hibernate4.1.3 and h2-1.3.166 following is my hibernate configuration:
<?xml version="1.0" encoding="ASCII"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate- configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.connection.driver_class">org.h2.Driver</property> <property name="hibernate.connection.url">jdbc:h2:~/Test</ property> <property name="hibernate.connection.username">user</property> <property name="hibernate.connection.password">password</ property> <property name="hibernate.connection.pool_size">10</property> <property name="dialect">org.hibernate.dialect.H2Dialect</ property> <property name="current_session_context_class">thread</property> <property name="show_sql">false</property> <property name="hbm2ddl.auto">update</property> <!-- Disable the second-level cache --> <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</ property> <!-- Mapping files --> <mapping resource="com/mywork/bean/Test.hbm.xml" /> </session-factory> </hibernate-configuration> Following is Test.java : public class Test implements Serializable { private static final long serialVersionUID = 127384653092245202L; private Long id; private String name; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } } Follwing is Test.hbm.xml <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com.mywork.bean"> <class name="Test" table="TEST"> <meta attribute="class-description"> This is sample class </meta> <id name="id" column="ID" type="long" /> <property name="name" column="NAME"/> </class> <query name="FindTestById"> <![CDATA[ from Test as test where test.id = ? ]]> </query> </hibernate-mapping> Following is code to insert row Session db = getSession(); // get org.hibernate.Session try { db.beginTransaction(); Test test = new Test(); test.setId(1L); test.setName(""); db.save(test); db.getTransaction().commit(); } catch(Exception e) { db.getTransaction().rollback(); e.printStrack(); } finally { if(db != null) { try { db.close(); } catch(Exception ee) { // Ignore exception } } } Following is code to query row Session db = getSession(); // get org.hibernate.Session try { db.beginTransaction(); List<Test> list = db.getNamedQuery("FindTestById").setLong(0, 1L).list(); if (list != null && list.size() > 0) { Test t = list.get(0); System.out.println(t.getId()); System.out.println(t.getName()); // <<< It return space that i found it is non-breaking space (\u00A0 in Unicode format) } } catch(Exception e) { e.printStrack(); } finally { if(db != null) { try { db.close(); } catch(Exception ee) { // Ignore exception } } } -- You received this message because you are subscribed to the Google Groups "H2 Database" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/h2-database?hl=en.
