-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate return null objects
PostPosted: Tue Feb 21, 2012 11:34 am 
Newbie

Joined: Tue Feb 21, 2012 7:38 am
Posts: 2
Hi.
I've used reverse engineering to create POJO classes from existing database (Pervasive database).
When i'm trying to get all records, in list i have null objects.
But in database they exist.
If one of fields "dataod" or "datado" are null in database, whole records is changed to null.
If both fields are set, i have object in my list, if one missing i have null.

Any ideas ?

Code:
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
      session.beginTransaction();

      List<Ck> list = (List<Ck>) session.createCriteria(Ck.class).list();

      session.getTransaction().commit();


My classes (generated by Hibernate Tools):
Code:
@Entity
@Table(name = "CK", catalog = "NOWY3", uniqueConstraints = { @UniqueConstraint(columnNames = "id"), @UniqueConstraint(columnNames = "kod") })
public class Ck implements java.io.Serializable {

   private CkId id;

   public Ck() {
   }

   public Ck(CkId id) {
      this.id = id;
   }

   @EmbeddedId
   @AttributeOverrides({ @AttributeOverride(name = "id", column = @Column(name = "id", unique = true)),
         @AttributeOverride(name = "kod", column = @Column(name = "kod", unique = true, length = 40)),
         @AttributeOverride(name = "subtyp", column = @Column(name = "subtyp")),
         @AttributeOverride(name = "opis", column = @Column(name = "opis", length = 40)),
         @AttributeOverride(name = "dataod", column = @Column(name = "dataod", nullable = true)),
         @AttributeOverride(name = "datado", column = @Column(name = "datado", nullable = true)),
         @AttributeOverride(name = "cenowy", column = @Column(name = "cenowy")),
         @AttributeOverride(name = "kontrah", column = @Column(name = "kontrah")),
         @AttributeOverride(name = "zapas", column = @Column(name = "zapas", length = 30)) })
   public CkId getId() {
      return this.id;
   }

   public void setId(CkId id) {
      this.id = id;
   }


Code:
@Embeddable
public class CkId implements java.io.Serializable {

   private Integer id;
   private String kod;
   private Byte subtyp;
   private String opis;
   private Serializable dataod;
   private Serializable datado;
   private Boolean cenowy;
   private Boolean kontrah;
   private String zapas;

   public CkId() {
   }

   public CkId(Integer id, String kod, Byte subtyp, String opis, Serializable dataod, Serializable datado, Boolean cenowy, Boolean kontrah,
         String zapas) {
      this.id = id;
      this.kod = kod;
      this.subtyp = subtyp;
      this.opis = opis;
      this.dataod = dataod;
      this.datado = datado;
      this.cenowy = cenowy;
      this.kontrah = kontrah;
      this.zapas = zapas;
   }

   @Column(name = "id", unique = true)
   public Integer getId() {
      return this.id;
   }

   public void setId(Integer id) {
      this.id = id;
   }

   @Column(name = "kod", unique = true, length = 40)
   public String getKod() {
      return this.kod;
   }

   public void setKod(String kod) {
      this.kod = kod;
   }

   @Column(name = "subtyp")
   public Byte getSubtyp() {
      return this.subtyp;
   }

   public void setSubtyp(Byte subtyp) {
      this.subtyp = subtyp;
   }

   @Column(name = "opis", length = 40)
   public String getOpis() {
      return this.opis;
   }

   public void setOpis(String opis) {
      this.opis = opis;
   }

   @Type(type = "date")
   @Column(name = "dataod", nullable = true)
   public Serializable getDataod() {
      return this.dataod;
   }

   public void setDataod(Serializable dataod) {
      this.dataod = dataod;
   }

   @Type(type = "date")
   @Column(name = "datado", nullable = true)
   public Serializable getDatado() {
      return this.datado;
   }

   public void setDatado(Serializable datado) {
      this.datado = datado;
   }

   @Column(name = "cenowy")
   public Boolean getCenowy() {
      return this.cenowy;
   }

   public void setCenowy(Boolean cenowy) {
      this.cenowy = cenowy;
   }

   @Column(name = "kontrah")
   public Boolean getKontrah() {
      return this.kontrah;
   }

   public void setKontrah(Boolean kontrah) {
      this.kontrah = kontrah;
   }

   @Column(name = "zapas", length = 30)
   public String getZapas() {
      return this.zapas;
   }

   public void setZapas(String zapas) {
      this.zapas = zapas;
   }
}


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

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.