Note that there are some explanatory texts on larger screens.

plurals
  1. POhibernate returning null objects
    primarykey
    data
    text
    <p>i am new in using hibernate and for some reason i am getting a list of null objects when i am using the following code:</p> <pre><code>public static void main(String args[]) { Session s = HibernateUtil.currentSession(); ArrayList lst = (ArrayList) s.createQuery("from Users").list(); for(Object obj : lst){ Users user = (Users)obj; System.Out.println(user.getUserid()); // null } } </code></pre> <p>my hibernate mapping xml looks like this:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"&gt; &lt;!-- Generated Dec 27, 2012 9:48:45 PM by Hibernate Tools 3.4.0.CR1 --&gt; &lt;hibernate-mapping&gt; &lt;class name="us.Users" table="USERS"&gt; &lt;id name="userid" type="int"&gt; &lt;column name="USERID" precision="9" scale="0" /&gt; &lt;generator class="assigned" /&gt; &lt;/id&gt; &lt;property name="username" type="string"&gt; &lt;column name="USERNAME" length="200" /&gt; &lt;/property&gt; &lt;property name="password" type="string"&gt; &lt;column name="PASSWORD" length="200" /&gt; &lt;/property&gt; &lt;property name="firstName" type="string"&gt; &lt;column name="FIRST_NAME" length="200" /&gt; &lt;/property&gt; &lt;property name="lastName" type="string"&gt; &lt;column name="LAST_NAME" length="200" /&gt; &lt;/property&gt; &lt;property name="dateOfBirth" type="timestamp"&gt; // my guess was that the problem appears with the timestamp property &lt;column name="DATE_OF_BIRTH" /&gt; &lt;/property&gt; &lt;property name="registrationDate" type="timestamp"&gt; &lt;column name="REGISTRATION_DATE" /&gt; &lt;/property&gt; &lt;one-to-one name="administrators" class="assignment2.Administrators"&gt;&lt;/one-to-one&gt; &lt;set name="histories" table="HISTORY" inverse="true" lazy="false" fetch="select"&gt; &lt;key&gt; &lt;column name="USERID" precision="9" scale="0" not-null="true" /&gt; &lt;/key&gt; &lt;one-to-many class="us.History" /&gt; &lt;/set&gt; &lt;set name="loginlogs" table="LOGINLOG" inverse="true" lazy="false" fetch="select"&gt; &lt;key&gt; &lt;column name="USERID" precision="9" scale="0" not-null="true" /&gt; &lt;/key&gt; &lt;one-to-many class="us.Loginlog" /&gt; &lt;/set&gt; &lt;/class&gt; </code></pre> <p></p> <p>here is my hibernate.cfg.xml :</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt; &lt;hibernate-configuration&gt; &lt;session-factory&gt; &lt;property name="hibernate.bytecode.use_reflection_optimizer"&gt;false&lt;/property&gt; &lt;property name="hibernate.connection.driver_class"&gt;oracle.jdbc.driver.OracleDriver&lt;/property&gt; &lt;property name="hibernate.connection.password"&gt;abcd&lt;/property&gt; &lt;property name="hibernate.connection.url"&gt;jdbc:oracle:thin:@localhost:1521:xe&lt;/property&gt; &lt;property name="hibernate.connection.username"&gt;SYSTEM&lt;/property&gt; &lt;property name="hibernate.default_schema"&gt;SYSTEM&lt;/property&gt; &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.Oracle10gDialect&lt;/property&gt; &lt;property name="hibernate.search.autoregister_listeners"&gt;false&lt;/property&gt; &lt;mapping resource="assignment2/History.hbm.xml" /&gt; &lt;mapping resource="assignment2/Similarity.hbm.xml" /&gt; &lt;mapping resource="assignment2/Loginlog.hbm.xml" /&gt; &lt;mapping resource="assignment2/Users.hbm.xml" /&gt; &lt;mapping resource="assignment2/Administrators.hbm.xml" /&gt; &lt;mapping resource="assignment2/Mediaitems.hbm.xml" /&gt; &lt;/session-factory&gt; </code></pre> <p></p> <p>and the users class:</p> <pre><code>/** * Users generated by hbm2java */ public class Users implements java.io.Serializable { private int userid; private String username; private String password; private String firstName; private String lastName; private Date dateOfBirth; private Date registrationDate; private Administrators administrators; private Set&lt;History&gt; histories = new HashSet&lt;History&gt;(0); private Set&lt;Loginlog&gt; loginlogs = new HashSet&lt;Loginlog&gt;(0); public Users() { } public Users(int userid) { this.userid = userid; } public Users(int userid, String username, String password, String firstName, String lastName, Serializable dateOfBirth, Serializable registrationDate, Administrators administrators, Set&lt;History&gt; histories, Set&lt;Loginlog&gt; loginlogs) { this.userid = userid; this.username = username; this.password = password; this.firstName = firstName; this.lastName = lastName; this.dateOfBirth = dateOfBirth; this.registrationDate = registrationDate; this.administrators = administrators; this.histories = histories; this.loginlogs = loginlogs; } public int getUserid() { return this.userid; } public void setUserid(int userid) { this.userid = userid; } public String getUsername() { return this.username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return this.password; } public void setPassword(String password) { this.password = password; } public String getFirstName() { return this.firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return this.lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public Date getDateOfBirth() { return this.dateOfBirth; } public void setDateOfBirth(Date dateOfBirth) { this.dateOfBirth = dateOfBirth; } public Date getRegistrationDate() { return this.registrationDate; } public void setRegistrationDate(Date registrationDate) { this.registrationDate = registrationDate; } public Administrators getAdministrators() { return this.administrators; } public void setAdministrators(Administrators administrators) { this.administrators = administrators; } public Set&lt;History&gt; getHistories() { return this.histories; } public void setHistories(Set&lt;History&gt; histories) { this.histories = histories; } public Set&lt;Loginlog&gt; getLoginlogs() { return this.loginlogs; } public void setLoginlogs(Set&lt;Loginlog&gt; loginlogs) { this.loginlogs = loginlogs; } </code></pre> <p>}</p> <p>thanks alot in advance</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload