[hibernate-issues] [Hibernate-JIRA] Created: (EJB-399) Collecitons in Associated Objects should never be null per EJB 3.0 Specification 2.1.7 Entity Relationships
Jon Kofal (JIRA)
noreply at atlassian.com
Thu Oct 30 10:45:04 EDT 2008
Collecitons in Associated Objects should never be null per EJB 3.0 Specification 2.1.7 Entity Relationships
-----------------------------------------------------------------------------------------------------------
Key: EJB-399
URL: http://opensource.atlassian.com/projects/hibernate/browse/EJB-399
Project: Hibernate Entity Manager
Issue Type: Bug
Components: EntityManager
Affects Versions: 3.3.1.GA
Environment: Windows XP, JRE 1.6.0_07
Reporter: Jon Kofal
"EJB 3.0 Specification 2.1.7 Entity Relationships" says (last paragraph):
"If there are no associated entities for a multi-valued relationship of an entity fetched from the database,
the persistence provider is responsible for returning an empty collection as the value of the relationship."
This code below throws a NullPointerException, because the Collection returned from "p.getReports()" is null. I'd expect that p.getReports() wold return an empty Collection per the EJB 3.0 Specification.
public void testProjectReport() throws Exception {
EntityManager em = null;
try {
em = emf.createEntityManager();
em.getTransaction().begin();
Projekt p = new Projekt();
p.setName(PROJEKT[0]);
em.persist(p);
p = (Projekt) em.createQuery("from Projekt").getSingleResult();
for (Iterator<Report> i = p.getReports().iterator(); i.hasNext();) {
logger.info(i.next().toString());
}
em.getTransaction().commit();
} catch (Exception e) {
logger.log(Level.SEVERE, e.getMessage(), e);
throw e;
} finally {
if (em != null) {
em.close();
}
}
}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list