The following query doesn’t return any rows
List remedies = session.createQuery(“from Remedy”).list();
No errors, but nothing in the remedies list and there are rows in the table.
What I have is 2 tables: remedy and remedyTranslation
I have the following map files:
remedy.hbm.xml is below:
<?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>
<class name="com.audiClave.Service.Remedy" table="REMEDY">
<id column="REMEDY_ID" name="remedy_id" type="int">
<generator class="native"/>
</id>
<property generated="never" lazy="false" name="name">
<column name="NAME"/>
</property>
<set
name="remedyTranslations"
lazy="true"
inverse="true"
cascade="save-update">
<key column="REMEDY_ID"/>
<one-to-many class="com.audiClave.Service.RemedyTranslation"/>
</set>
</class>
</hibernate-mapping>
remedyTranslation.hbm.xml is below:
<?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>
<class name="com.audiClave.Service.RemedyTranslation" table="REMEDYTRANSLATION">
<id column="REMEDYTRANSLATION_ID" name="remedyTranslation_id" type="int">
<generator class="native"/>
</id>
<many-to-one
name="remedy_id"
column="REMEDY_ID"
class="com.audiClave.Service.Remedy"
not-null="true"
lazy="false" />
<property generated="never" lazy="false" name="name">
<column name="NAME"/>
</property>
<property generated="never" lazy="false" name="language">
<column name="LANGUAGE"/>
</property>
</class>
</hibernate-mapping>
hibernate.cfg.xml:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/userdata</property>
<property name="connection.username">mysql</property>
<property name="connection.password">???????</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">update</property>
<!-- Mapping files -->
<mapping resource="remedy.hbm.xml"/>
<mapping resource="remedyTranslation.hbm.xml"/>
</session-factory>
</hibernate-configuration>
If what andrew posted doesn’t work, turn your hibernate logging on to show sql statements and see if you are actually making any sql requests. If there are no requests, the problem lies in your configuration, if there is a bad request then you’ll know it’s in your class.