hi all,
when i try to retreive from data base it is returning an empty list.
i am using Oracle 10g db.
i have two tables namely CRMACCOUNT and CRMUSER and java classes for them Crmaccount.java and Crmuser.java. i have a main class AccountDAO in which i try to fetch data from the CRMACCOUNT table.
the query works fine in SQL plus its not working when i run it using Hibernate.
the output is:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Hibernate: select crmaccount0_.ACCOUNTID as ACCOUNTID3_, crmaccount0_.DELETEDUSER as DELETEDU2_3_, crmaccount0_.ASSIGNEDBY as ASSIGNEDBY3_, crmaccount0_.ASSIGNEDTO as ASSIGNEDTO3_, crmaccount0_.ACCOUNTNAME as ACCOUNTN5_3_, crmaccount0_.INDUSTRY as INDUSTRY3_, crmaccount0_.WEBSITE as WEBSITE3_, crmaccount0_.PRIMARYPHONE as PRIMARYP8_3_, crmaccount0_.SECONDARYPHONE as SECONDAR9_3_, crmaccount0_.PRIMARYEMAIL as PRIMARY10_3_, crmaccount0_.SECONDARYEMAIL as SECONDA11_3_, crmaccount0_.STREET as STREET3_, crmaccount0_.COUNTRY as COUNTRY3_, crmaccount0_.STATE as STATE3_, crmaccount0_.PINCODE as PINCODE3_, crmaccount0_.DESCRIPTION as DESCRIP16_3_, crmaccount0_.PROIRITY as PROIRITY3_ from user.CRMACCOUNT crmaccount0_
List empty
but my CRMACCOUNT table contains one row..!!!
The main file: AccountDAO
package com.pojo;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.Query;
import java.util.Iterator;
import java.util.List;
public class AccounDAO {
private static SessionFactory fac;
private static Session ses;
public static void main(String[] args) {
fac = new Configuration().configure().buildSessionFactory();
ses = fac.openSession();
Transaction ts = ses.getTransaction();
ts.begin();
Query q=ses.createQuery("from Crmaccount");
List accountdetails=q.list();
if(accountdetails.isEmpty()){
System.out.println("List empty");
}
ts.commit();
ses.close();
}
}
Crmaccount.java
package com.pojo;
public class Crmaccount {
private Integer accountid;
private Crmuser crmuserByDeleteduser;
private Crmuser crmuserByAssignedby;
private Crmuser crmuserByAssignedto;
private String accountname;
private String industry;
private String website;
private String primaryphone;
private String secondaryphone;
private String primaryemail;
private String secondaryemail;
private String street;
private String country;
private String state;
private Integer pincode;
private String description;
private Integer proirity;
public Crmaccount() {
}
public Crmaccount(Integer accountid) {
this.accountid = accountid;
}
public Crmaccount(Integer accountid, Crmuser crmuserByDeleteduser, Crmuser crmuserByAssignedby, Crmuser crmuserByAssignedto, String accountname, String industry, String website, String primaryphone, String secondaryphone, String primaryemail, String secondaryemail, String street, String country, String state, Integer pincode, String description, Integer proirity) {
this.accountid = accountid;
this.crmuserByDeleteduser = crmuserByDeleteduser;
this.crmuserByAssignedby = crmuserByAssignedby;
this.crmuserByAssignedto = crmuserByAssignedto;
this.accountname = accountname;
this.industry = industry;
this.website = website;
this.primaryphone = primaryphone;
this.secondaryphone = secondaryphone;
this.primaryemail = primaryemail;
this.secondaryemail = secondaryemail;
this.street = street;
this.country = country;
this.state = state;
this.pincode = pincode;
this.description = description;
this.proirity = proirity;
}
public Integer getAccountid() {
return this.accountid;
}
public void setAccountid(Integer accountid) {
this.accountid = accountid;
}
public Crmuser getCrmuserByDeleteduser() {
return this.crmuserByDeleteduser;
}
public void setCrmuserByDeleteduser(Crmuser crmuserByDeleteduser) {
this.crmuserByDeleteduser = crmuserByDeleteduser;
}
public Crmuser getCrmuserByAssignedby() {
return this.crmuserByAssignedby;
}
public void setCrmuserByAssignedby(Crmuser crmuserByAssignedby) {
this.crmuserByAssignedby = crmuserByAssignedby;
}
public Crmuser getCrmuserByAssignedto() {
return this.crmuserByAssignedto;
}
public void setCrmuserByAssignedto(Crmuser crmuserByAssignedto) {
this.crmuserByAssignedto = crmuserByAssignedto;
}
public String getAccountname() {
return this.accountname;
}
public void setAccountname(String accountname) {
this.accountname = accountname;
}
public String getIndustry() {
return this.industry;
}
public void setIndustry(String industry) {
this.industry = industry;
}
public String getWebsite() {
return this.website;
}
public void setWebsite(String website) {
this.website = website;
}
public String getPrimaryphone() {
return this.primaryphone;
}
public void setPrimaryphone(String primaryphone) {
this.primaryphone = primaryphone;
}
public String getSecondaryphone() {
return this.secondaryphone;
}
public void setSecondaryphone(String secondaryphone) {
this.secondaryphone = secondaryphone;
}
public String getPrimaryemail() {
return this.primaryemail;
}
public void setPrimaryemail(String primaryemail) {
this.primaryemail = primaryemail;
}
public String getSecondaryemail() {
return this.secondaryemail;
}
public void setSecondaryemail(String secondaryemail) {
this.secondaryemail = secondaryemail;
}
public String getStreet() {
return this.street;
}
public void setStreet(String street) {
this.street = street;
}
public String getCountry() {
return this.country;
}
public void setCountry(String country) {
this.country = country;
}
public String getState() {
return this.state;
}
public void setState(String state) {
this.state = state;
}
public Integer getPincode() {
return this.pincode;
}
public void setPincode(Integer pincode) {
this.pincode = pincode;
}
public String getDescription() {
return this.description;
}
public void setDescription(String description) {
this.description = description;
}
public Integer getProirity() {
return this.proirity;
}
public void setProirity(Integer proirity) {
this.proirity = proirity;
}
}
CrmUser.Java
package com.pojo;
import java.util.HashSet;
import java.util.Set;
public class Crmuser implements java.io.Serializable {
private String username;
private Integer userid;
private String password;
private Set crmaccountsForAssignedby = new HashSet(0);
private Set crmaccountsForAssignedto = new HashSet(0);
private Set crmaccountsForDeleteduser = new HashSet(0);
public Crmuser() {
}
public Crmuser(String username) {
this.username = username;
}
public Crmuser(String username, Integer userid, String password, Set crmaccountsForAssignedby, Set crmaccountsForAssignedto, Set crmaccountsForDeleteduser) {
this.username = username;
this.userid = userid;
this.password = password;
this.crmaccountsForAssignedby = crmaccountsForAssignedby;
this.crmaccountsForAssignedto = crmaccountsForAssignedto;
this.crmaccountsForDeleteduser = crmaccountsForDeleteduser;
}
public String getUsername() {
return this.username;
}
public void setUsername(String username) {
this.username = username;
}
public Integer getUserid() {
return this.userid;
}
public void setUserid(Integer userid) {
this.userid = userid;
}
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
public Set getCrmaccountsForAssignedby() {
return this.crmaccountsForAssignedby;
}
public void setCrmaccountsForAssignedby(Set crmaccountsForAssignedby) {
this.crmaccountsForAssignedby = crmaccountsForAssignedby;
}
public Set getCrmaccountsForAssignedto() {
return this.crmaccountsForAssignedto;
}
public void setCrmaccountsForAssignedto(Set crmaccountsForAssignedto) {
this.crmaccountsForAssignedto = crmaccountsForAssignedto;
}
public Set getCrmaccountsForDeleteduser() {
return this.crmaccountsForDeleteduser;
}
public void setCrmaccountsForDeleteduser(Set crmaccountsForDeleteduser) {
this.crmaccountsForDeleteduser = crmaccountsForDeleteduser;
}
}
Mapping Files for the same :
crmuser.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>
<class name="com.pojo.Crmuser" table="CRMUSER" >
<id name="username" type="string">
<column name="USERNAME" length="12" />
<generator class="assigned" />
</id>
<property name="userid" type="java.lang.Short">
<column name="USERID" precision="4" scale="0" />
</property>
<property name="password" type="string">
<column name="PASSWORD" length="12" />
</property>
<set name="crmaccountsForAssignedby" inverse="true">
<key>
<column name="ASSIGNEDBY" length="12" />
</key>
<one-to-many class="com.pojo.Crmaccount" />
</set>
<set name="crmaccountsForAssignedto" inverse="true">
<key>
<column name="ASSIGNEDTO" length="12" />
</key>
<one-to-many class="com.pojo.Crmaccount" />
</set>
<set name="crmaccountsForDeleteduser" inverse="true">
<key>
<column name="DELETEDUSER" length="12" />
</key>
<one-to-many class="com.pojo.Crmaccount" />
</set>
</class>
</hibernate-mapping>
crmaccount.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>
<class name="com.pojo.Crmaccount" table="CRMACCOUNT" >
<id name="accountid" type="integer">
<column name="ACCOUNTID" precision="4" scale="0" />
<generator class="assigned" />
</id>
<many-to-one name="crmuserByDeleteduser" class="com.pojo.Crmuser" fetch="select">
<column name="DELETEDUSER" length="12" />
</many-to-one>
<many-to-one name="crmuserByAssignedby" class="com.pojo.Crmuser" fetch="select">
<column name="ASSIGNEDBY" length="12" />
</many-to-one>
<many-to-one name="crmuserByAssignedto" class="com.pojo.Crmuser" fetch="select">
<column name="ASSIGNEDTO" length="12" />
</many-to-one>
<property name="accountname" type="string">
<column name="ACCOUNTNAME" length="25" />
</property>
<property name="industry" type="string">
<column name="INDUSTRY" length="10" />
</property>
<property name="website" type="string">
<column name="WEBSITE" length="25" />
</property>
<property name="primaryphone" type="string">
<column name="PRIMARYPHONE" length="10" />
</property>
<property name="secondaryphone" type="string">
<column name="SECONDARYPHONE" length="10" />
</property>
<property name="primaryemail" type="string">
<column name="PRIMARYEMAIL" length="25" />
</property>
<property name="secondaryemail" type="string">
<column name="SECONDARYEMAIL" length="25" />
</property>
<property name="street" type="string">
<column name="STREET" length="25" />
</property>
<property name="country" type="string">
<column name="COUNTRY" length="10" />
</property>
<property name="state" type="string">
<column name="STATE" length="10" />
</property>
<property name="pincode" type="java.lang.Integer">
<column name="PINCODE" precision="6" scale="0" />
</property>
<property name="description" type="string">
<column name="DESCRIPTION" length="30" />
</property>
<property name="proirity" type="integer">
<column name="PROIRITY" precision="1" scale="0" />
</property>
</class>
</hibernate-mapping>
Hibernate Config File:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">"connecton_url"</property>
<property name="connection.username">username</property>
<property name="connection.password">password</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.OracleDialect</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 resource="com/crmuser.hbm.xml"/>
<mapping resource="com/crmaccount.hbm.xml"/>
</session-factory>
</hibernate-configuration>
there are someforeign key relations between the two tables. is that causing the problem?
please post ur reply.
PS: i am new to this forum. so pardon me if am violating any posting rules..
|