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