Reputation: 2209
I am trying to use Hibernate but when I execute a query I receive a list of my entity where all the attributes are NULL. The thing is that when i use the jdbc directly I am able to retrieve the values from my Db. I read similar articles about NULL values but couldn't figure out what s wrong in my case. Below you see: 1) My entity: Eshop
public class Eshop implements java.io.Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
public Eshop() {}
public Eshop(int eshopId, String code, String name, String lastModified) {
this.eshopId = eshopId;
this.code = code;
this.name = name;
this.lastModified = lastModified;
}
public int eshopId;
public String code;
public String name;
public String lastModified;
public int getEshopId() {
return eshopId;
}
public void setEshopId(int eshopId) {
eshopId = eshopId;
}
public String getCode() {
return code;
}
public void setCode(String code) {
code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
name = name;
}
public String getLastModified() {
return lastModified;
}
public void setLastModified(String lastModified) {
lastModified = lastModified;
}
2) The Hibernate Mapping
<hibernate-mapping>
<class name="dataModel.Eshop" table="Eshop">
<meta attribute="class-description">
This class contains the Eshop details.
</meta>
<id name="eshopId" type="int" column="EshopId">
<generator class="native"/>
</id>
<property name="code" column="Code" type="string"/>
<property name="name" column="Name" type="string"/>
<property name="lastModified" column="LastModified" type="string"/>
</class>
</hibernate-mapping>
And this is how I run the query:
Configuration config = new Configuration().configure();
SessionFactory sessionFactory = config.buildSessionFactory();
Session session = sessionFactory.getCurrentSession();
session.beginTransaction();
Query hibernateQuery = session.createQuery("from Eshop");
List<Eshop> Eshops = hibernateQuery.list();
So when I run a query i receive the exact number of Eshops which are in my Db but all their attributes values are null!! An ideas?? Thank you
Upvotes: 0
Views: 627
Reputation: 8387
Try to add hibernate.cfg.xml
like this:
Configuration config = new Configuration().configure("hibernate.cfg.xml");
Upvotes: 0
Reputation: 691635
All your setters are wrong:
public void setEshopId(int eshopId) {
eshopId = eshopId;
}
This is a noop. It should be
public void setEshopId(int eshopId) {
this.eshopId = eshopId;
}
Upvotes: 3