Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
2.1
Mapping documents:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping
>
<class
name="com.tietoenator.dk.lub.model.integrationlayer.test.Player"
table="PLAYER"
dynamic-update="false"
dynamic-insert="false"
select-before-update="false"
optimistic-lock="version"
>
<id
name="playerId"
column="PLAYER_ID"
type="long"
>
<generator class="native">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-Player.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>
<many-to-one
name="team"
class="com.tietoenator.dk.lub.model.integrationlayer.test.Team"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
column="TEAM_ID"
not-null="true"
/>
<property
name="annualSalary"
type="float"
update="true"
insert="true"
access="property"
column="ANNUAL_SALARY"
not-null="false"
unique="false"
/>
<property
name="draftDate"
type="timestamp"
update="true"
insert="true"
access="property"
column="DRAFT_DATE"
not-null="false"
unique="false"
/>
<property
name="firstName"
type="string"
update="true"
insert="true"
access="property"
column="FIRST_NAME"
length="20"
not-null="true"
unique="false"
/>
<property
name="jerseyNumber"
type="int"
update="true"
insert="true"
access="property"
column="JERSEY_NUMBER"
not-null="true"
unique="false"
/>
<property
name="lastName"
type="string"
update="true"
insert="true"
access="property"
column="LAST_NAME"
length="20"
not-null="true"
unique="false"
/>
<property
name="endDate"
type="timestamp"
update="true"
insert="true"
access="property"
column="END_DATE"
not-null="true"
unique="false"
/>
<property
name="startDate"
type="timestamp"
update="true"
insert="true"
access="property"
column="START_DATE"
not-null="true"
unique="false"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Player.xml
containing the additional properties and place it in your merge dir.
-->
</class>
<query name="findAllPlayers"><![CDATA[
from com.tietoenator.dk.lub.model.integrationlayer.test.Player
]]></query>
</hibernate-mapping>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping
>
<class
name="com.tietoenator.dk.lub.model.integrationlayer.test.Team"
table="TEAM"
dynamic-update="false"
dynamic-insert="false"
select-before-update="false"
optimistic-lock="version"
>
<id
name="teamId"
column="TEAM_ID"
type="java.lang.Long"
>
<generator class="native">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-Team.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>
<set
name="players"
lazy="true"
inverse="true"
cascade="all-delete-orphan"
sort="unsorted"
>
<key
column="TEAM_ID"
>
</key>
<one-to-many
class="com.tietoenator.dk.lub.model.integrationlayer.test.Player"
/>
</set>
<property
name="city"
type="string"
update="true"
insert="true"
access="property"
column="CITY"
length="20"
not-null="false"
unique="false"
/>
<property
name="teamName"
type="string"
update="true"
insert="true"
access="property"
column="TEAM_NAME"
length="20"
not-null="false"
unique="false"
/>
<property
name="endDate"
type="timestamp"
update="true"
insert="true"
access="property"
column="END_DATE"
not-null="true"
unique="false"
/>
<property
name="startDate"
type="timestamp"
update="true"
insert="true"
access="property"
column="START_DATE"
not-null="true"
unique="false"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Team.xml
containing the additional properties and place it in your merge dir.
-->
</class>
<query name="findIdByTeamName"><![CDATA[
select team.teamId from com.tietoenator.dk.lub.model.integrationlayer.test.Team team where team.teamName = :teamName
]]></query>
<query name="findAllTeams"><![CDATA[
from com.tietoenator.dk.lub.model.integrationlayer.test.Team
]]></query>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
StringBuffer buffer = new StringBuffer();
StringResultBean result = new StringResultBean();
try {
Query query = this.getSession().getNamedQuery("findAllTeams");
Iterator teams = query.iterate();
while (teams.hasNext()) {
Team team = (Team) teams.next();
buffer.append("Team ID : " + team.getTeamId() + "\n");
buffer.append("Team : " + team.getTeamName() + "\n");
buffer.append("City : " + team.getCity() + "\n");
buffer.append("StartDate : " + (""+team.getStartDate()).substring(0,10) + "\n");
buffer.append("EndDate : " + (""+team.getEndDate()).substring(0,10) + "\n");
buffer.append("\n");
}
} catch (HibernateException e) {
System.out.println(e.getMessage());
buffer.append("Could not get all the teams\n");
buffer.append(e.getMessage());
}
result.setResult(buffer.toString());
req.setAttribute("result", result);
// Forward control to the specified success URI
return (mapping.findForward("success"));
Full stack trace of any exception that occurs:
[25-02-05 10:17:55:433 CET] 65b7dd71 SystemOut O You may not dereference a collection with cascade="all-delete-orphan"
[25-02-05 10:17:55:443 CET] 65b7dd71 RequestProces W org.apache.struts.action.RequestProcessor Unhandled Exception thrown: class net.sf.hibernate.HibernateException
[25-02-05 10:17:55:443 CET] 65b7dd71 WebGroup E SRVE0026E: [Servlet Error]-[You may not dereference a collection with cascade="all-delete-orphan"]: net.sf.hibernate.HibernateException: You may not dereference a collection with cascade="all-delete-orphan"
at net.sf.hibernate.impl.SessionImpl.updateUnreachableCollection(SessionImpl.java:2951)
at net.sf.hibernate.impl.SessionImpl.flushCollections(SessionImpl.java:2816)
at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2282)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2260)
at com.tietoenator.dk.lub.controller.action.core.DoAction.execute(DoAction.java:31)
at com.tietoenator.dk.lub.controller.action.test.ShowAllTeamsAction.execute(ShowAllTeamsAction.java:57)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:948)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:530)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:176)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:79)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:201)
at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:610)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:435)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java(Compiled Code))
Name and version of the database you are using:
DB2
The generated SQL (show_sql=true):
[25-02-05 10:17:55:373 CET] 65b7dd71 SystemOut O Hibernate: select team0_.TEAM_ID as x0_0_ from TEAM team0_
[25-02-05 10:17:55:383 CET] 65b7dd71 SystemOut O Hibernate: select team0_.TEAM_ID as TEAM_ID0_, team0_.CITY as CITY0_, team0_.TEAM_NAME as TEAM_NAME0_, team0_.END_DATE as END_DATE0_, team0_.START_DATE as START_DATE0_ from TEAM team0_ where team0_.TEAM_ID=?
[25-02-05 10:17:55:393 CET] 65b7dd71 SystemOut O Hibernate: select players0_.TEAM_ID as TEAM_ID__, players0_.PLAYER_ID as PLAYER_ID__, players0_.PLAYER_ID as PLAYER_ID0_, players0_.TEAM_ID as TEAM_ID0_, players0_.ANNUAL_SALARY as ANNUAL_S3_0_, players0_.DRAFT_DATE as DRAFT_DATE0_, players0_.FIRST_NAME as FIRST_NAME0_, players0_.JERSEY_NUMBER as JERSEY_N6_0_, players0_.LAST_NAME as LAST_NAME0_, players0_.END_DATE as END_DATE0_, players0_.START_DATE as START_DATE0_ from PLAYER players0_ where players0_.TEAM_ID=?
[25-02-05 10:17:55:403 CET] 65b7dd71 SystemOut O Hibernate: select team0_.TEAM_ID as TEAM_ID0_, team0_.CITY as CITY0_, team0_.TEAM_NAME as TEAM_NAME0_, team0_.END_DATE as END_DATE0_, team0_.START_DATE as START_DATE0_ from TEAM team0_ where team0_.TEAM_ID=?
[25-02-05 10:17:55:403 CET] 65b7dd71 SystemOut O Hibernate: select players0_.TEAM_ID as TEAM_ID__, players0_.PLAYER_ID as PLAYER_ID__, players0_.PLAYER_ID as PLAYER_ID0_, players0_.TEAM_ID as TEAM_ID0_, players0_.ANNUAL_SALARY as ANNUAL_S3_0_, players0_.DRAFT_DATE as DRAFT_DATE0_, players0_.FIRST_NAME as FIRST_NAME0_, players0_.JERSEY_NUMBER as JERSEY_N6_0_, players0_.LAST_NAME as LAST_NAME0_, players0_.END_DATE as END_DATE0_, players0_.START_DATE as START_DATE0_ from PLAYER players0_ where players0_.TEAM_ID=?
[25-02-05 10:17:55:403 CET] 65b7dd71 SystemOut O Hibernate: select team0_.TEAM_ID as TEAM_ID0_, team0_.CITY as CITY0_, team0_.TEAM_NAME as TEAM_NAME0_, team0_.END_DATE as END_DATE0_, team0_.START_DATE as START_DATE0_ from TEAM team0_ where team0_.TEAM_ID=?
[25-02-05 10:17:55:403 CET] 65b7dd71 SystemOut O Hibernate: select players0_.TEAM_ID as TEAM_ID__, players0_.PLAYER_ID as PLAYER_ID__, players0_.PLAYER_ID as PLAYER_ID0_, players0_.TEAM_ID as TEAM_ID0_, players0_.ANNUAL_SALARY as ANNUAL_S3_0_, players0_.DRAFT_DATE as DRAFT_DATE0_, players0_.FIRST_NAME as FIRST_NAME0_, players0_.JERSEY_NUMBER as JERSEY_N6_0_, players0_.LAST_NAME as LAST_NAME0_, players0_.END_DATE as END_DATE0_, players0_.START_DATE as START_DATE0_ from PLAYER players0_ where players0_.TEAM_ID=?
[25-02-05 10:17:55:403 CET] 65b7dd71 SystemOut O Hibernate: select team0_.TEAM_ID as TEAM_ID0_, team0_.CITY as CITY0_, team0_.TEAM_NAME as TEAM_NAME0_, team0_.END_DATE as END_DATE0_, team0_.START_DATE as START_DATE0_ from TEAM team0_ where team0_.TEAM_ID=?
[25-02-05 10:17:55:403 CET] 65b7dd71 SystemOut O Hibernate: select players0_.TEAM_ID as TEAM_ID__, players0_.PLAYER_ID as PLAYER_ID__, players0_.PLAYER_ID as PLAYER_ID0_, players0_.TEAM_ID as TEAM_ID0_, players0_.ANNUAL_SALARY as ANNUAL_S3_0_, players0_.DRAFT_DATE as DRAFT_DATE0_, players0_.FIRST_NAME as FIRST_NAME0_, players0_.JERSEY_NUMBER as JERSEY_N6_0_, players0_.LAST_NAME as LAST_NAME0_, players0_.END_DATE as END_DATE0_, players0_.START_DATE as START_DATE0_ from PLAYER players0_ where players0_.TEAM_ID=?
[25-02-05 10:17:55:403 CET] 65b7dd71 SystemOut O Hibernate: select team0_.TEAM_ID as TEAM_ID0_, team0_.CITY as CITY0_, team0_.TEAM_NAME as TEAM_NAME0_, team0_.END_DATE as END_DATE0_, team0_.START_DATE as START_DATE0_ from TEAM team0_ where team0_.TEAM_ID=?
[25-02-05 10:17:55:403 CET] 65b7dd71 SystemOut O Hibernate: select players0_.TEAM_ID as TEAM_ID__, players0_.PLAYER_ID as PLAYER_ID__, players0_.PLAYER_ID as PLAYER_ID0_, players0_.TEAM_ID as TEAM_ID0_, players0_.ANNUAL_SALARY as ANNUAL_S3_0_, players0_.DRAFT_DATE as DRAFT_DATE0_, players0_.FIRST_NAME as FIRST_NAME0_, players0_.JERSEY_NUMBER as JERSEY_N6_0_, players0_.LAST_NAME as LAST_NAME0_, players0_.END_DATE as END_DATE0_, players0_.START_DATE as START_DATE0_ from PLAYER players0_ where players0_.TEAM_ID=?
[25-02-05 10:17:55:403 CET] 65b7dd71 SystemOut O Hibernate: select team0_.TEAM_ID as TEAM_ID0_, team0_.CITY as CITY0_, team0_.TEAM_NAME as TEAM_NAME0_, team0_.END_DATE as END_DATE0_, team0_.START_DATE as START_DATE0_ from TEAM team0_ where team0_.TEAM_ID=?
[25-02-05 10:17:55:403 CET] 65b7dd71 SystemOut O Hibernate: select players0_.TEAM_ID as TEAM_ID__, players0_.PLAYER_ID as PLAYER_ID__, players0_.PLAYER_ID as PLAYER_ID0_, players0_.TEAM_ID as TEAM_ID0_, players0_.ANNUAL_SALARY as ANNUAL_S3_0_, players0_.DRAFT_DATE as DRAFT_DATE0_, players0_.FIRST_NAME as FIRST_NAME0_, players0_.JERSEY_NUMBER as JERSEY_N6_0_, players0_.LAST_NAME as LAST_NAME0_, players0_.END_DATE as END_DATE0_, players0_.START_DATE as START_DATE0_ from PLAYER players0_ where players0_.TEAM_ID=?
[25-02-05 10:17:55:403 CET] 65b7dd71 SystemOut O Hibernate: select team0_.TEAM_ID as TEAM_ID0_, team0_.CITY as CITY0_, team0_.TEAM_NAME as TEAM_NAME0_, team0_.END_DATE as END_DATE0_, team0_.START_DATE as START_DATE0_ from TEAM team0_ where team0_.TEAM_ID=?
[25-02-05 10:17:55:403 CET] 65b7dd71 SystemOut O Hibernate: select players0_.TEAM_ID as TEAM_ID__, players0_.PLAYER_ID as PLAYER_ID__, players0_.PLAYER_ID as PLAYER_ID0_, players0_.TEAM_ID as TEAM_ID0_, players0_.ANNUAL_SALARY as ANNUAL_S3_0_, players0_.DRAFT_DATE as DRAFT_DATE0_, players0_.FIRST_NAME as FIRST_NAME0_, players0_.JERSEY_NUMBER as JERSEY_N6_0_, players0_.LAST_NAME as LAST_NAME0_, players0_.END_DATE as END_DATE0_, players0_.START_DATE as START_DATE0_ from PLAYER players0_ where players0_.TEAM_ID=?
[25-02-05 10:17:55:403 CET] 65b7dd71 SystemOut O Hibernate: select team0_.TEAM_ID as TEAM_ID0_, team0_.CITY as CITY0_, team0_.TEAM_NAME as TEAM_NAME0_, team0_.END_DATE as END_DATE0_, team0_.START_DATE as START_DATE0_ from TEAM team0_ where team0_.TEAM_ID=?
[25-02-05 10:17:55:403 CET] 65b7dd71 SystemOut O Hibernate: select players0_.TEAM_ID as TEAM_ID__, players0_.PLAYER_ID as PLAYER_ID__, players0_.PLAYER_ID as PLAYER_ID0_, players0_.TEAM_ID as TEAM_ID0_, players0_.ANNUAL_SALARY as ANNUAL_S3_0_, players0_.DRAFT_DATE as DRAFT_DATE0_, players0_.FIRST_NAME as FIRST_NAME0_, players0_.JERSEY_NUMBER as JERSEY_N6_0_, players0_.LAST_NAME as LAST_NAME0_, players0_.END_DATE as END_DATE0_, players0_.START_DATE as START_DATE0_ from PLAYER players0_ where players0_.TEAM_ID=?
Debug level Hibernate log excerpt:
So far I know that if I try to change a collection with a cascade="all-delete-orphan" I will get this exception, but I can't see whay I am getting it here as I am not doing anything with the collection