when querying Oracle views with Hibernate 4, I return a list with a size greater than 0 representing the number of elements that I get when I run the same query in SQL Developer, for example. When I scroll through the list, I get only null values.
My hibernate.cfg.xml looks like this:
<?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> <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property> <property name="hibernate.connection.url">jdbc:oracle:thin:@127.0.0.1:1521:OUT</property> <property name="hibernate.connection.username">username</property> <property name="hibernate.connection.password">password</property> <property name="hibernate.default_schema">schema</property> <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property> <property name="hibernate.connection.pool_size">1</property> <property name="hibernate.current_session_context_class">thread</property> <property name="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</property> <property name="hibernate.hbm2ddl.auto">update</property> <mapping resource="be/comp/model/db/VwPersoneelslid.hbm.xml"/> </session-factory>
VwPersoneelslid.hbm.xml looks like this:
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="be.comp.model.db.VwPersoneelslid" table="VW_PERSONEELSLID"> <composite-id name="id" class="be.comp.model.db.VwPersoneelslidId"> <key-property name="pkVwPersoneelslid" type="double"> <column name="PK_VW_PERSONEELSLID" precision="126" scale="0" /> </key-property> <key-property name="fkVwFunctie" type="double"> <column name="FK_VW_FUNCTIE" precision="126" scale="0" /> </key-property> <key-property name="familienaam" type="string"> <column name="FAMILIENAAM" length="80" /> </key-property> <key-property name="voornaam" type="string"> <column name="VOORNAAM" length="80" /> </key-property> <key-property name="code" type="string"> <column name="CODE" length="10" /> </key-property> </composite-id> </class>
Function with request:
public List<VwPersoneelslid> findByCode(String code) { Session session = HibernateUtil.getSessionFactoryNeptunus().getCurrentSession(); session.beginTransaction(); List<VwPersoneelslid> list = new ArrayList(); Query query = session.createQuery("FROM VwPersoneelslid WHERE code = :code"); query.setParameter("code", code); list = query.list(); session.getTransaction().commit(); return list; }
Function converted to native SQL:
public List<VwPersoneelslid> findByCode(String code) { Session session = HibernateUtil.getSessionFactoryNeptunus().getCurrentSession(); session.beginTransaction(); List<VwPersoneelslid> list = new ArrayList(); Query query = session.createSQLQuery("SELECT * FROM CIPALII.VW_PERSONEELSLID WHERE code = :code").addEntity(VwPersoneelslid.class) .setParameter("code", code); list = query.list(); session.getTransaction().commit(); return list; }
If you guys need more information to find out what might be the problem, let me know and I will add more code. The VwPersoneelslid.hbm.xml file is automatically generated by Eclipse. Thanks.
hibernate
Snels nick
source share