-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate Reads Nulls in OneToMany Array
PostPosted: Wed Jan 29, 2014 11:41 am 
Newbie

Joined: Wed Jan 29, 2014 10:35 am
Posts: 2
Hallo, I have a very unusual problem here,
My program worrked pretty good till now, but suddenly it loads nulls in my OneToMany connected lists.
I will show this here,
Here is my class persis, all classes that will be able to load something from the database will inheritate this class.
Code:
public void load(Session session, long ID) throws HibernateException{
        Transaction tx = session.beginTransaction();
        try{
            session.load(this, ID);
            session.flush();
            tx.commit();
            session.clear();
        }catch(HibernateException ex){
            ex.printStackTrace();
            tx.rollback();
            session.clear();
            throw new HibernateException(ex);
        }
       
    }
    public void saveOrUpdate(Session session) throws HibernateException{
        Transaction tx = session.beginTransaction();
        try{
            session.saveOrUpdate(this);
            session.flush();
            tx.commit();
            session.clear();
        }catch(HibernateException ex){
            ex.printStackTrace();
            tx.rollback();
            session.clear();
            throw new HibernateException(ex);
        }
    }
    public void delete(Session session) throws HibernateException{
        Transaction tx = session.beginTransaction();
        try{
           
            session.delete(this);
            session.flush();
            tx.commit();
            session.clear();
        }catch(HibernateException ex){
            ex.printStackTrace();
            tx.rollback();
            session.clear();
            throw new HibernateException(ex);
        }
    }
    public void merge(Session session) throws HibernateException{
        Transaction tx = session.beginTransaction();
        try{
            session.merge(this);
            session.flush();
            tx.commit();
            session.clear();
        }catch(HibernateException ex){
            ex.printStackTrace();
            tx.rollback();
            session.clear();
            throw new HibernateException(ex);
        }
    }

Here is my class article
Code:
@Entity
@Table(name = "artikel")
@Inheritance(strategy=InheritanceType.JOINED)
public class Artikel extends Persis implements Serializable {
   
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "artikel_seq")
    @SequenceGenerator(name = "artikel_seq", sequenceName = "artikel_seq", initialValue = 1000, allocationSize = 1)
    @Column(name="pk_artikel")
    private long ID;
   
    @Column(name="bezeichnung", length = 80)
    private String bezeichnung;
   
    @Column(name="einkaufspreis")
    private double lfEinkaufspreis;
   
    @Column(name="verkaufspreis")
    private double lfVerkaufspreis;
   
    @Column(name="abwertung")
    private double lfAbwertung;
   
    @JoinColumn(name="fk_marke", referencedColumnName="pk_marke")
    @OneToOne
    private Marke obMarke;
   
    @Column(name="einkaufsdatum")
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date einkaufsdatum;
   
    @Column(name="stueckzahl")
    private int intStueckZahl;
   
    @Column(name="vkpberechnung")
    private String vkpBerechnen;
   
    @Column(name="artikelnummer", length = 25)
    private String artikelnummer;

    @ManyToOne
    Kunde obKunde;

here my class schmuckstücke
Code:
@Entity
@Table(name="schmuckstueck")
@PrimaryKeyJoinColumn(name="pk_schmuckstueck", referencedColumnName="pk_artikel")
public class Schmuckstueck extends Artikel{
   
    @OneToMany(mappedBy="schmuckstueck", targetEntity=Edelmetall.class, orphanRemoval=true, cascade= CascadeType.ALL)
    @LazyCollection(LazyCollectionOption.FALSE)
    @OrderColumn(name="pk_edelmetall")
    private List<Edelmetall> alEdelmetall;
   
    @OneToMany(mappedBy="schmuckstueck", targetEntity=Edelstein.class, orphanRemoval=true, cascade= CascadeType.ALL)
    @OrderColumn(name="pk_edelstein")
    @LazyCollection(LazyCollectionOption.FALSE)
    private List<Edelstein> alEdelsteine;
   
    @Column(name="art")
    private String art;

I hope i posted everything importent, otherwise pls write what other data you need. This is how i load my schmuckstueck.
Code:
Session ses = HibernateUtil.getInstance().getCurrentSession();
        selectedArtikel.load(ses, selectedArtikel.getID());

When i do the loading it loads nulls in my lists alEdelsteine and alEdelmetalle and I don t know why. It always loads n-1 nulls in the lists, this means, when I have 4 elements in the database it loads 3 null elements and then it loads the 4 elements. I am using Hibernate 3.6.10 final
I hope somebody can help me.

Lg Vincenz


Top
 Profile  
 
 Post subject: Re: Hibernate Reads Nulls in OneToMany Array
PostPosted: Mon Feb 03, 2014 10:11 am 
Newbie

Joined: Wed Jan 29, 2014 10:35 am
Posts: 2
This error does not occure in hibernate 3.2.... if anyone may be can help me with this.


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

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.