-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: Session.find() returning empty list
PostPosted: Wed Jan 14, 2004 5:01 pm 
Newbie

Joined: Wed Jan 14, 2004 4:44 pm
Posts: 13
Location: Wellington, New Zealand
Using Hibernate 2.1.1 and Oracle 8.1

Session.find() is returning an empty list.

The code I am using is:

Transaction tx = session.beginTransaction();
List leavingReasons = session.find("from LeavingReason as leavingReason order by leavingReason.id");

// leavingReasons is empty here

The Log shows correctly generated SQL:

select leavingrea0_.ID as ID, leavingrea0_.name as name, leavingrea0_.description as descript3_, leavingrea0_.valid as valid from Leaving_Reasons leavingrea0_ order by leavingrea0_.ID

and the SQL executes as expected when I run it in the Oracle console.

Any ideas?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2004 5:04 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Well, no data in DB ?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2004 5:08 pm 
Newbie

Joined: Wed Jan 14, 2004 4:44 pm
Posts: 13
Location: Wellington, New Zealand
I copied the generated SQL from the log and ran it in the Oracle console and it returned the correct results, so the data is definitely there.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2004 5:12 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Show the (simplified) mapping, pojo model implementation, code showing this is an empty list. Check you're pointing the right DB.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2004 5:32 pm 
Newbie

Joined: Wed Jan 14, 2004 4:44 pm
Posts: 13
Location: Wellington, New Zealand
Mapping:
<hibernate-mapping package="nz.govt.msd.inet.HR.HRExit">
<class name="LeavingReason" table="Leaving_Reasons">
<id name="id" type="long" unsaved-value="null" >
<column name="ID" sql-type="number(9)" not-null="true"/>
<generator class="sequence">
<param name="sequence">SEQ_EXIT_INTERVIEW</param>
</generator>
</id>
<property name="name">
<column name="name" sql-type="varchar2(100)"/>
</property>
<property name="description">
<column name="description" sql-type="varchar2(200)"/>
</property>
<property name="valid">
<column name="valid" sql-type="varchar2(1)"/>
</property>
<set name="exitReasons" lazy="true">
<key column="ID"/>
<one-to-many class="ExitReason"/>
</set>
</class>
...
</hibernate-mapping>

POJO:
package nz.govt.msd.inet.HR.HRExit;

import java.util.Set;

public class LeavingReason {

private Long id;
private String name;
private String description;
private String valid;
private Set exitReasons;

public LeavingReason() {}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

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

public String getValid() {
return valid;
}

public void setValid(String valid) {
this.valid = valid;
}

public Set getExitReasons() {
return exitReasons;
}

public void setExitReasons(Set exitReasons) {
this.exitReasons = exitReasons;
}

public void addExitReason(ExitReason exitReason) {
exitReason.getLeavingReason().getExitReasons().remove(exitReason);
exitReason.setLeavingReason(this);
exitReasons.add(exitReason);
}
}

Code:
try {
Session session = HibernateUtil.currentSession();
Transaction tx = session.beginTransaction();
List leavingReasons = session.find("from LeavingReason as leavingReason order by leavingReason.id");
logger.info("Size of list: " + new Integer(leavingReasons.size())); //logs "0"
tx.commit();
HibernateUtil.closeSession();
} catch (HibernateException ex) {
logger.fatal(ex);
// TODO: add error to ActionErrors collection.
return (mapping.findForward("error"));
}

Note: I use HibernateUtil.currentSession() in another part of the application to insert into another table and it works successfully, so I should be pointing to the right DB.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2004 5:42 pm 
Newbie

Joined: Wed Jan 14, 2004 4:44 pm
Posts: 13
Location: Wellington, New Zealand
Duh! I have DDL and DML in script files to build the tables and insert the initial data. I didn't commit the inserts in the script files!

Sorry! Thanks for your help Emmanuel.

Russell


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 15, 2004 3:12 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
BTW,
Code:
<set name="exitReasons" lazy="true">
<key column="ID"/>
<one-to-many class="ExitReason"/>
</set>

is broken
key column should refer to the FK column in ExitReason table. Have a llok at the cat sample (5.1 in reference guide)

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.