Note that there are some explanatory texts on larger screens.

plurals
  1. POEager loading in Hibernate doesnt work, referenced attrribute has null values
    primarykey
    data
    text
    <p>i have a hibernate problem, probably due to lazy/eager loading or something similiar. I have a model class student and a model class century. The student has an attribute century. Before I save the stdent in the dao i save the referenced century. But when I save the student, the century is null everywhere, except for it's name. I tried @Fetch(FetchMode.JOIN), @ManyToOne(fetch = FetchType.EAGER) and getHibernateTemplate().initialize(student.getCentury()); so far but nothing will work. Some ideas would be great, thanks in advance!</p> <p>Student class:</p> <pre><code>// @Fetch(FetchMode.JOIN) @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "CENTURY_ID") public Century getCentury() { return century; } </code></pre> <p>StudentDao:</p> <p>load-method inherited from SuperDao:</p> <pre><code>@SuppressWarnings("unchecked") public T load(Long id) { T object = (T) getSession().get( classOfData, id); log.error(String.format("%s with id %d loaded.", CLASS_NAME_OF_DATA, id)); if (object == null) { log.error("Object not found"); } return object; } </code></pre> <p>save method in StudentDao:</p> <pre><code> @Override public Student save(Student student) throws HibernateException { // getHibernateTemplate().initialize(student.getCentury()); log.error("Saving student:" + student.toString()); Century century = centuryDao.load(student.getCentury().getId()); System.out.println("instudentdao:" + century.getManiple()); centuryDao.save(student.getCentury()); getSession().saveOrUpdate(student); log.error(String.format("Student with id %d saved.", student.getId())); return student; } </code></pre> <p>StudentAction load method is passed down to Dao:</p> <pre><code>private void loadStudent(String id) { create = request.getParameter("mode").equals("create"); edit = request.getParameter("mode").equals("edit"); view = request.getParameter("mode").equals("view"); if (request.getParameter("mode").equals("create")) student = new Student(); else student = studentService.load(Long.valueOf(id)); } </code></pre> <p>log for (fetch = FetchType.EAGER)</p> <pre><code>2013-11-17 13:15:59,819 ERROR http-bio-8080-exec-9 - &lt;Saving student:Student [id=1, firstName=hans, lastName=wurst, gender=null, city=HAMBURG, postalCode=22123, street=SHEMALESTREET, streetNumber=23, company=Company [id=null, name1=OLE, name2=null, nameShort=null, city=null, postalCode=null, street=null, streetNumber=null, email=null, phone=null, fax=null, status=null, supervisors=null], phone=1234123, email=olko@olko.olko, century=Century [id=null, name=Zenturie, maniple=null, students=null], birthday=Sun Jan 01 00:00:00 CET 2012, birthPlace=MUELLTONNE, userId=123, addressAddition=, status=ACTIVE, supervisor=Supervisor [id=null, firstName=null, lastName=, company=null, email=null, phone=null]]&gt; </code></pre> <p>log for @JoinColumn(name = "CENTURY_ID")</p> <pre><code>2013-11-17 13:22:25,266 ERROR http-bio-8080-exec-10 - &lt;Saving student:Student [id=1, firstName=hans, lastName=wurst, gender=null, city=HAMBURG, postalCode=22123, street=SHEMALESTREET, streetNumber=23, company=Company [id=null, name1=OLE, name2=null, nameShort=null, city=null, postalCode=null, street=null, streetNumber=null, email=null, phone=null, fax=null, status=null, supervisors=null], phone=1234123, email=olko@olko.olko, century=Century [id=null, name=Zenturie, maniple=null, students=null], birthday=Sun Jan 01 00:00:00 CET 2012, birthPlace=MUELLTONNE, userId=123, addressAddition=, status=ACTIVE, supervisor=Supervisor [id=null, firstName=null, lastName=, company=null, email=null, phone=null]]&gt; </code></pre> <p>log for initialize()</p> <pre><code>2013-11-17 13:25:01,381 ERROR http-bio-8080-exec-10 - &lt;Saving student:Student [id=1, firstName=hans, lastName=wurst, gender=null, city=HAMBURG, postalCode=22123, street=SHEMALESTREET, streetNumber=23, company=Company [id=null, name1=OLE, name2=null, nameShort=null, city=null, postalCode=null, street=null, streetNumber=null, email=null, phone=null, fax=null, status=null, supervisors=null], phone=1234123, email=olko@olko.olko, century=Century [id=null, name=Zenturie, maniple=null, students=null], birthday=Sun Jan 01 00:00:00 CET 2012, birthPlace=MUELLTONNE, userId=123, addressAddition=, status=ACTIVE, supervisor=Supervisor [id=null, firstName=null, lastName=, company=null, email=null, phone=null]]&gt; </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.
    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