Hi to all, i am using from clause but it is not working ,i get null value , select query works fine.
When i use from i get following message "
Hibernate: select address0_.id as col_0_0_ from ADDRESS address0_ null " this is my code plz tell me where is error
package hiber.scr; import java.util.Iterator; import org.hibernate.*; import org.hibernate.cfg.*;
import java.util.*; public class FirstExample { public static void main(String[] args) { Session session = null;
try{ // This step will read hibernate.cfg.xml and prepare hibernate for use SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); session =sessionFactory.openSession(); // String SQL_QUERY ="Select insurance.addressId,insurance.street," + // "insurance.city,insurance.state from Address insurance"; //Using from Clause String SQL_QUERY ="from Address add"; Query query = session.createQuery(SQL_QUERY); for(Iterator it=query.iterate();it.hasNext();){ Address add=(Address)it.next(); System.out.println("ID: " +add.getAddressId() ); } session.close(); }catch(Exception e){ System.out.println(e.getMessage()); }finally{ }
} } ------------------------------------------------------------------------------------------
<?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="hiber.scr.Address" table="ADDRESS"> <meta attribute="class-description">This class contains the student's address details.</meta> <id name="addressId" type="long" column="id"> <generator class="identity" /> </id> <property name="street" column="street" /> <property name="city" column="city" /> <property name="state" column="state" /> <property name="zipcode" column="zipcode" /> </class> </hibernate-mapping> -------------------------------------------------------------------------
package hiber.scr;
public class Address { private long addressId; private String street; private String city; private String state; private String zipcode; public Address(String street, String city, String state, String zipcode) { this.street = street; this.city = city; this.state = state; this.zipcode = zipcode; }
public long getAddressId() { return addressId; }
public void setAddressId(long addressId) { this.addressId = addressId; }
public String getStreet() { return street; }
public void setStreet(String street) { this.street = street; }
public String getCity() { return city; }
public void setCity(String city) { this.city = city; }
public String getState() { return state; }
public void setState(String state) { this.state = state; }
public String getZipcode() { return zipcode; }
public void setZipcode(String zipcode) { this.zipcode = zipcode; } } ---------------------------------------------
<?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration> <session-factory> <property name="hibernate.connection.driver_class"> com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url"> jdbc:mysql://localhost/hibernate</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password"></property> <property name="hibernate.connection.pool_size">10</property> <property name="show_sql">true</property> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <property name="hibernate.hbm2ddl.auto">update</property> <!-- Mapping files --> <mapping resource="contact.hbm.xml" /> <mapping resource="student.hbm.xml" /> <mapping resource="Address.hbm.xml" /> </session-factory> </hibernate-configuration>
------------------------------------------------------------------------------------- thanks
|