Note that there are some explanatory texts on larger screens.

plurals
  1. POobject references an unsaved transient instance error
    primarykey
    data
    text
    <p>Ok so i want to get mapped Groups and student in one table but i've got an error: "object references an unsaved transient instance". If i add cascade to all it will say that this objects arleady exists. What is wrong ?</p> <p>Here are entities:</p> <pre><code> @Entity @Table(name = "listaosob") public class listaOsob implements Serializable { @Id @GeneratedValue private int id; private static final long serialVersionUID = 1L; @ManyToOne private Student student; @ManyToOne private Grupa grupa; @Entity @Table(name = "student") public class Student implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue private int id; private String imie; private String nazwisko; private String login; private String haslo; @Column(unique=true) private int nr_albumu; @Column(unique=true) private String kod_karty; @Entity @Table(name = "grupa") public class Grupa implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue private int id; private String nazwa; private Time godzina; private String sala; private String tydzien; @ManyToOne private Prowadzacy prowadzacy; </code></pre> <p>ejb code:</p> <pre><code> @Stateless @LocalBean public class StudentBean implements StudentBeanRemote, StudentBeanLocal { @PersistenceContext private EntityManager eM; public StudentBean() {} public void dodajStudenta(Student s) { eM.persist(s); eM.flush(); } public void usunStudenta(Student s) { eM.remove(s); eM.flush(); } @SuppressWarnings("unchecked") public ArrayList&lt;Student&gt; listaStudentow() { Query query = eM.createQuery("SELECT e FROM student e"); return (ArrayList&lt;Student&gt;) query.getResultList(); } @SuppressWarnings("unchecked") public ArrayList&lt;Student&gt; listaStudentow(Grupa grupa) { Query query = eM.createQuery("SELECT e FROM listaosob e WHERE e.grupa = :grupa"); query.setParameter("grupa", grupa); return (ArrayList&lt;Student&gt;) query.getResultList(); } public void dodajGrupe(Grupa g) { eM.persist(g); } public void usunGrupe(Grupa g) { eM.remove(g); eM.flush(); } public void dodajListeOsob(listaOsob l) { eM.persist(l); } </code></pre> <p>and a example test:</p> <pre><code>Student name1 = new Student("new"+gen.nextInt(),"nazwisko","log", "haslo", "asd"+gen.nextInt(), gen.nextInt()); obj.dodajStudenta(name1); Grupa n = new Grupa(); obj.dodajGrupe(n); listaOsob lista = new listaOsob(name1, n); obj.dodajListeOsob(lista); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload