Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
3.2.6
Mapping documents:
<hibernate-mapping>
<class entity-name="Agents" table="AGENTS" schema="COMPASS_MI">
<id name="guid" type="string">
<column name="GUID" length="36" />
<generator class="assigned" />
</id>
<bag name="agentParticipantses" inverse="true" cascade="all">
<key>
<column name="A_GUID" length="36" not-null="true"/>
</key>
<one-to-many entity-name="AgentParticipants" />
</bag>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class entity-name="Participants" table="PARTICIPANTS" schema="COMPASS_MI">
<id name="guid" type="string">
<column name="GUID" length="36" />
<generator class="assigned" />
</id>
<bag name="agentParticipantses" inverse="true" cascade="all">
<key>
<column name="P_GUID" length="36" not-null="true"/>
</key>
<one-to-many entity-name="AgentParticipants" />
</bag>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class entity-name="AgentParticipants" table="AGENT_PARTICIPANTS" schema="COMPASS_MI">
<id name="guid" type="string">
<column name="GUID" length="36" />
<generator class="assigned" />
</id>
<many-to-one name="participants" entity-name="Participants" fetch="select">
<column name="P_GUID" length="36" not-null="true"/>
</many-to-one>
<many-to-one name="agents" entity-name="Agents" fetch="select">
<column name="A_GUID" length="36" not-null="true"/>
</many-to-one>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Map<String,Object> agent = new HashMap<String,Object>();
agent.put("guid", "012345678901234567890123456789123456");
Map<String,Object> participant = new HashMap<String,Object>();
participant.put("guid", "012345678901234567890123456789123456");
Map<String,Object> agentParticipant = new HashMap<String,Object>();
agentParticipant.put("guid", "012345678901234567890123456789123456");
agentParticipant.put("agents", agent);
agentParticipant.put("participants", participant);
agent.put("agentParticipantses", new ArrayList());
((List)agent.get("agentParticipantses")).add(agentParticipant);
participant.put("agentParticipantses", new ArrayList());
((List)participant.get("agentParticipantses")).add(agentParticipant);
sessionFactory.getCurrentSession().persist("Agents", agent);
// unsure if this step is redundant in this scheme
sessionFactory.getCurrentSession().persist("Participants", participant);
sessionFactory.getCurrentSession().flush();
/*
* Once the supporting objects are inserted, attempt to retrieve the agent participant
*/
Map<String,Object> returnedObject = (Map<String,Object>) sessionFactory.getCurrentSession().
createQuery("from AgentParticipants entity where entity.agents.guid = :guid").
setString("guid", "012345678901234567890123456789123456").uniqueResult();
assertNotNull(returnedObject);
Full stack trace of any exception that occurs:
org.hibernate.PropertyValueException: not-null property references a null or transient value: AgentParticipants.participants
at org.hibernate.engine.Nullability.checkNullability(Nullability.java:72)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:290)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:121)
at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:131)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:87)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:609)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:601)
at org.hibernate.engine.CascadingAction$8.cascade(CascadingAction.java:295)
at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:216)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:296)
at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:242)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:219)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
at org.hibernate.event.def.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:456)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:334)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:121)
at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:131)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:87)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:38)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:618)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:592)
at com.ciminc.compass.test.general.HibernateDynamicMaps.testDependencyHibernate(HibernateDynamicMaps.java:127)
..then some junit/spring stuff
Name and version of the database you are using:
Oracle 10g
The generated SQL (show_sql=true):
never does the inserts for the 3 entities used, but attempts the select for the AgentParticipant entity