My Problem is as follows. I have a many to many assosiation between environments and servers. It all seems to be fine, I get no error if I want to save some data (see Java Code below).
But my relation table (ecm_server_environment_data) contains no Data! Server and Environment Entities are saved but not the relation between them. Can you help?
Hibernate version:
3.3.2.GA
Mapping documents:
EcmEnvironmentData
Code:
<hibernate-mapping>
<class name="com.basfits.insite.core.environmentData.EcmEnvironmentData" table="ecm_environment_data" catalog="ecm">
<id name="persistentId" type="java.lang.Long">
<column name="environment_id" />
<generator class="identity" />
</id>
<many-to-one name="ecmRuntimeEnvironment" class="com.basfits.insite.core.environmentRuntime.EcmRuntimeEnvironment" fetch="select">
<column name="runtime_environment_Id" />
</many-to-one>
<property name="name" type="java.lang.String">
<column name="name" length="50" />
</property>
<property name="context" type="java.lang.String">
<column name="context" length="250" />
</property>
<property name="version" type="java.lang.Float">
<column name="version" precision="12" scale="0" />
</property>
<bag name="ecmServers" table="ecm_server_environment_data" cascade="all">
<key column="environment_data_id" />
<many-to-many class="com.basfits.insite.core.server.EcmServer" column="server_id" />
</bag>
<set name="ecmHistories" inverse="true">
<key>
<column name="environment_data_id" not-null="true" />
</key>
<one-to-many class="com.basfits.insite.core.history.EcmHistory" />
</set>
<bag name="ecmClusters" inverse="true">
<key>
<column name="environment_data_id" />
</key>
<one-to-many class="com.basfits.insite.core.cluster.EcmCluster" />
</bag>
</class>
</hibernate-mapping>
EcmServer
Code:
<hibernate-mapping>
<class name="com.basfits.insite.core.server.EcmServer" table="ecm_server" catalog="ecm">
<id name="persistentId" type="java.lang.Long">
<column name="server_id" />
<generator class="identity" />
</id>
<many-to-one name="ecmCluster" class="com.basfits.insite.core.cluster.EcmCluster" fetch="select">
<column name="cluster_id" />
</many-to-one>
<property name="name" type="java.lang.String">
<column name="name" length="50" not-null="true" />
</property>
<property name="description" type="java.lang.String">
<column name="description" length="65535" />
</property>
<property name="url" type="java.lang.String">
<column name="url" length="250" not-null="true" />
</property>
<property name="port" type="java.lang.Integer">
<column name="port" not-null="true" />
</property>
<set name="ecmPortals" table="ecm_portal_server" inverse="true" lazy="true">
<key>
<column name="server_id" not-null="true" />
</key>
<many-to-many class="com.basfits.insite.core.portal.EcmPortal" />
</set>
<bag name="ecmEnvironmentDatas" cascade="all" table="ecm_server_environment_data">
<key column="server_id" />
<many-to-many class="com.basfits.insite.core.environmentData.EcmEnvironmentData" column="environment_id"/>
</bag>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
EcmServer server1 = new EcmServer("String", "String", new Integer(9091));
EcmEnvironmentData data = new EcmEnvironmentData();
data.setName("NAME");
data.setContext("/group");
data.getEcmServers().add(server1);
environmentDataDao.save(data);
Log:
16:28:46,218 DEBUG [EcmEnvironmentDataDAO] saving EcmEnvironmentData instance
16:28:46,531 DEBUG [SessionImpl] opened session at timestamp: 12366125263
16:28:46,531 DEBUG [DefaultSaveOrUpdateEventListener] saving transient instance
16:28:46,546 DEBUG [AbstractSaveEventListener] saving [com.basfits.insite.core.environmentData.EcmEnvironmentData#<null>]
16:28:46,546 DEBUG [AbstractSaveEventListener] executing insertions
16:28:46,562 DEBUG [Cascade] processing cascade ACTION_SAVE_UPDATE for: com.basfits.insite.core.environmentData.EcmEnvironmentData
16:28:46,562 DEBUG [Cascade] done processing cascade ACTION_SAVE_UPDATE for: com.basfits.insite.core.environmentData.EcmEnvironmentData
16:28:46,625 DEBUG [WrapVisitor] Wrapped collection in role: com.basfits.insite.core.environmentData.EcmEnvironmentData.ecmServers
16:28:46,640 DEBUG [WrapVisitor] Wrapped collection in role: com.basfits.insite.core.environmentData.EcmEnvironmentData.ecmHistories
16:28:46,640 DEBUG [WrapVisitor] Wrapped collection in role: com.basfits.insite.core.environmentData.EcmEnvironmentData.ecmClusters
16:28:46,687 DEBUG [AbstractSaveEventListener] executing identity-insert immediately
16:28:46,687 DEBUG [AbstractEntityPersister] Inserting entity: com.basfits.insite.core.environmentData.EcmEnvironmentData (native id)
16:28:46,703 DEBUG [AbstractBatcher] about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
16:28:46,703 DEBUG [ConnectionManager] opening JDBC connection
16:28:46,765 DEBUG [SQL]
insert
into
ecm.ecm_environment_data
(runtime_environment_Id, name, context, version)
values
(?, ?, ?, ?)
Hibernate:
insert
into
ecm.ecm_environment_data
(runtime_environment_Id, name, context, version)
values
(?, ?, ?, ?)
16:28:46,765 DEBUG [AbstractBatcher] preparing statement
16:28:46,781 DEBUG [AbstractEntityPersister] Dehydrating entity: [com.basfits.insite.core.environmentData.EcmEnvironmentData#<null>]
16:28:46,796 DEBUG [LongType] binding null to parameter: 1
16:28:46,796 DEBUG [StringType] binding 'BASF.COM' to parameter: 2
16:28:46,796 DEBUG [StringType] binding '/group' to parameter: 3
16:28:46,796 DEBUG [FloatType] binding null to parameter: 4
16:28:46,968 DEBUG [IdentifierGeneratorFactory] Natively generated identity: 33
16:28:46,968 DEBUG [AbstractBatcher] about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
16:28:46,968 DEBUG [AbstractBatcher] closing statement
16:28:46,984 DEBUG [Cascade] processing cascade ACTION_SAVE_UPDATE for: com.basfits.insite.core.environmentData.EcmEnvironmentData
16:28:46,984 DEBUG [Cascade] cascade ACTION_SAVE_UPDATE for collection: com.basfits.insite.core.environmentData.EcmEnvironmentData.ecmServers
16:28:47,000 DEBUG [CascadingAction] cascading to saveOrUpdate: com.basfits.insite.core.server.EcmServer
16:28:47,000 DEBUG [AbstractSaveEventListener] transient instance of: com.basfits.insite.core.server.EcmServer
16:28:47,000 DEBUG [DefaultSaveOrUpdateEventListener] saving transient instance
16:28:47,000 DEBUG [AbstractSaveEventListener] saving [com.basfits.insite.core.server.EcmServer#<null>]
16:28:47,000 DEBUG [AbstractSaveEventListener] executing insertions
16:28:47,000 DEBUG [Cascade] processing cascade ACTION_SAVE_UPDATE for: com.basfits.insite.core.server.EcmServer
16:28:47,000 DEBUG [Cascade] done processing cascade ACTION_SAVE_UPDATE for: com.basfits.insite.core.server.EcmServer
16:28:47,000 DEBUG [WrapVisitor] Wrapped collection in role: com.basfits.insite.core.server.EcmServer.ecmPortals
16:28:47,000 DEBUG [WrapVisitor] Wrapped collection in role: com.basfits.insite.core.server.EcmServer.ecmEnvironmentDatas
16:28:47,000 DEBUG [AbstractSaveEventListener] executing identity-insert immediately
16:28:47,000 DEBUG [AbstractEntityPersister] Inserting entity: com.basfits.insite.core.server.EcmServer (native id)
16:28:47,000 DEBUG [AbstractBatcher] about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
16:28:47,000 DEBUG [SQL]
insert
into
ecm.ecm_server
(cluster_id, name, description, url, port)
values
(?, ?, ?, ?, ?)
Hibernate:
insert
into
ecm.ecm_server
(cluster_id, name, description, url, port)
values
(?, ?, ?, ?, ?)
16:28:47,015 DEBUG [AbstractBatcher] preparing statement
16:28:47,015 DEBUG [AbstractEntityPersister] Dehydrating entity: [com.basfits.insite.core.server.EcmServer#<null>]
16:28:47,015 DEBUG [LongType] binding null to parameter: 1
16:28:47,015 DEBUG [StringType] binding 'string 1' to parameter: 2
16:28:47,015 DEBUG [StringType] binding null to parameter: 3
16:28:47,015 DEBUG [StringType] binding 'String' to parameter: 4
16:28:47,015 DEBUG [IntegerType] binding '9091' to parameter: 5
16:28:47,031 DEBUG [IdentifierGeneratorFactory] Natively generated identity: 42
16:28:47,046 DEBUG [AbstractBatcher] about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
16:28:47,046 DEBUG [AbstractBatcher] closing statement
16:28:47,046 DEBUG [Cascade] processing cascade ACTION_SAVE_UPDATE for: com.basfits.insite.core.server.EcmServer
16:28:47,046 DEBUG [Cascade] cascade ACTION_SAVE_UPDATE for collection: com.basfits.insite.core.server.EcmServer.ecmEnvironmentDatas
16:28:47,046 DEBUG [Cascade] done cascade ACTION_SAVE_UPDATE for collection: com.basfits.insite.core.server.EcmServer.ecmEnvironmentDatas
16:28:47,046 DEBUG [Cascade] done processing cascade ACTION_SAVE_UPDATE for: com.basfits.insite.core.server.EcmServer
16:28:47,046 DEBUG [Cascade] done cascade ACTION_SAVE_UPDATE for collection: com.basfits.insite.core.environmentData.EcmEnvironmentData.ecmServers
16:28:47,046 DEBUG [Cascade] done processing cascade ACTION_SAVE_UPDATE for: com.basfits.insite.core.environmentData.EcmEnvironmentData
16:28:47,046 DEBUG [EcmEnvironmentDataDAO] save successful