Mir stellt sich folgendes (hoffentlich banales Problem):
Ich habe in MySQL folgende Table:
CREATE TABLE `wsx_hib`.`wsx_group` (
`group_id` int(11) unsigned NOT NULL,
`org_id` int(11) unsigned NOT NULL,
`group_name` varchar(30) NOT NULL,
`lang_id` int(11) unsigned NOT NULL,
`lang_fixed` smallint(5) unsigned NOT NULL COMMENT 'Sprache fix eingestellt?',
`role_id` int(11) unsigned NOT NULL,
`group_system` smallint(5) unsigned NOT NULL,
PRIMARY KEY (`group_id`,`org_id`),
KEY `FK9DFE19C255F7A78` (`org_id`),
KEY `FK9DFE19C5C6FE781` (`lang_id`),
KEY `FK9DFE19C757FA2D7` (`role_id`,`org_id`),
CONSTRAINT `groupLang` FOREIGN KEY (`lang_id`) REFERENCES `wsx_lang` (`lang_id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `groupOrg1` FOREIGN KEY (`org_id`) REFERENCES `wsx_organization` (`org_id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `groupRole` FOREIGN KEY (`role_id`, `org_id`) REFERENCES `wsx_role` (`role_id`, `org_id`) ON DELETE CASCADE ON UPDATE CASCADE
)
Wenn ich ein Objekt dieser Instanz speichern will dann wird der FK nicht gesetzt und es entsteht eine Exception (da für den FK-Wert NOT NULL gesetzt wurde)
Wie man aus der SQL-Ausgabe entnehmen kann wird der FK-Werte (role_id) nicht gesetzt
Wie man dem Code weiter unten entnehmen kann, wird der Werte allerdings gesetzt
Der Werte der Rolle (WsxRole r) ist nicht null ( ;-) )
Hibernate version: 3.2.0.beta8
Mapping documents:
hibernate.cfg.xml:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.bytecode.use_reflection_optimizer">true</property>
<property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
<property name="hibernate.connection.password">1234567</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/wsx_hib</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="current_session_context_class">thread</property>
<property name="show_sql">true</property>
<mapping resource="tables/WsxFormQueue.hbm.xml" />
<mapping resource="tables/WsxLog.hbm.xml" />
<mapping resource="tables/WsxFormGrouping.hbm.xml" />
<mapping resource="tables/WsxGroup.hbm.xml" />
<mapping resource="tables/WsxFormLang.hbm.xml" />
<mapping resource="tables/WsxUser.hbm.xml" />
<mapping resource="tables/WsxUserSession.hbm.xml" />
<mapping resource="tables/WsxLang.hbm.xml" />
<mapping resource="tables/WsxFiletype.hbm.xml" />
<mapping resource="tables/WsxFormTitle.hbm.xml" />
<mapping resource="tables/WsxMsgLang.hbm.xml" />
<mapping resource="tables/WsxConfig.hbm.xml" />
<mapping resource="tables/WsxForm.hbm.xml" />
<mapping resource="tables/WsxDir.hbm.xml" />
<mapping resource="tables/WsxMsgGroup.hbm.xml" />
<mapping resource="tables/WsxRolePermission.hbm.xml" />
<mapping resource="tables/WsxFormGroupingLang.hbm.xml" />
<mapping resource="tables/WsxFormGroupVisible.hbm.xml" />
<mapping resource="tables/WsxFormHelp.hbm.xml" />
<mapping resource="tables/WsxOrganization.hbm.xml" />
<mapping resource="tables/WsxClient.hbm.xml" />
<mapping resource="tables/WsxPermission.hbm.xml" />
<mapping resource="tables/WsxFormClient.hbm.xml" />
<mapping resource="tables/WsxOrganizationUrl.hbm.xml" />
<mapping resource="tables/WsxQuery.hbm.xml" />
<mapping resource="tables/WsxFormSession.hbm.xml" />
<mapping resource="tables/WsxGroupMember.hbm.xml" />
<mapping resource="tables/WsxMsg.hbm.xml" />
<mapping resource="tables/WsxDirOpen.hbm.xml" />
<mapping resource="tables/WsxQueue.hbm.xml" />
<mapping resource="tables/WsxRole.hbm.xml" />
</session-factory>
</hibernate-configuration>
WsxGroup.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 08.01.2007 10:25:20 by Hibernate Tools 3.2.0.beta8 -->
<hibernate-mapping>
<class name="at.invaris.wsx.data.table.WsxGroup" table="wsx_group" catalog="wsx_hib">
<comment></comment>
<composite-id name="id" class="at.invaris.wsx.data.table.WsxGroupId">
<key-property name="groupId" type="int">
<column name="group_id" />
</key-property>
<key-property name="orgId" type="int">
<column name="org_id" />
</key-property>
</composite-id>
<many-to-one name="wsxOrganization" class="at.invaris.wsx.data.table.WsxOrganization" update="false" insert="false" fetch="select">
<column name="org_id" not-null="true">
<comment></comment>
</column>
</many-to-one>
<many-to-one name="wsxRole" class="at.invaris.wsx.data.table.WsxRole" update="false" insert="false" fetch="select">
<column name="role_id" not-null="true">
<comment></comment>
</column>
<column name="org_id" not-null="true">
<comment></comment>
</column>
</many-to-one>
<many-to-one name="wsxLang" class="at.invaris.wsx.data.table.WsxLang" fetch="select">
<column name="lang_id" not-null="true">
<comment></comment>
</column>
</many-to-one>
<property name="groupName" type="string">
<column name="group_name" length="30" not-null="true">
<comment></comment>
</column>
</property>
<property name="langFixed" type="short">
<column name="lang_fixed" not-null="true">
<comment>Sprache fix eingestellt?</comment>
</column>
</property>
<property name="groupSystem" type="short">
<column name="group_system" not-null="true">
<comment></comment>
</column>
</property>
<set name="wsxFormGroupVisibles" inverse="true">
<key>
<column name="org_id" not-null="true">
<comment></comment>
</column>
<column name="group_id" not-null="true">
<comment></comment>
</column>
</key>
<one-to-many class="at.invaris.wsx.data.table.WsxFormGroupVisible" />
</set>
<set name="wsxGroupMembers" inverse="true">
<key>
<column name="org_id" not-null="true">
<comment></comment>
</column>
<column name="group_id" not-null="true">
<comment></comment>
</column>
</key>
<one-to-many class="at.invaris.wsx.data.table.WsxGroupMember" />
</set>
<set name="wsxFormSessions" inverse="true">
<key>
<column name="group_id_to">
<comment></comment>
</column>
<column name="org_id" not-null="true">
<comment></comment>
</column>
</key>
<one-to-many class="at.invaris.wsx.data.table.WsxFormSession" />
</set>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
WsxRole r = getRole(org_id, role_id);
WsxGroupId gid = new WsxGroupId();
gid.setOrgId(org_id);
WsxGroup g = new WsxGroup();
g.setId(gid);
g.setWsxLang(l);
g.setGroupName(group_name);
g.setLangFixed( (short) lang_typ);
g.setWsxRole(r);
persist(g);
Full stack trace of any exception that occurs:
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:249)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:41)
at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:969)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1562)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at at.invaris.wsx.data.dbcon.getGroups(dbcon.java:189)
at at.invaris.wsx.www.settings.settings_organizations_show.get(settings_organizations_show.java:1873)
at at.invaris.wsx.www.settings.settings_main_show.get(settings_main_show.java:73)
at at.invaris.wsx.requests.WSXRequest.includePageRequest(WSXRequest.java:464)
at at.invaris.wsx.requests.WSXRequest.handlePageRequest(WSXRequest.java:331)
at at.invaris.wsx.requests.WSXRequest.handleRequest(WSXRequest.java:110)
at at.invaris.wsx.servlets.WSXServlet.handleRequest(WSXServlet.java:350)
at at.invaris.wsx.servlets.WSXServlet.doPost(WSXServlet.java:378)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.sql.BatchUpdateException: Field 'role_id' doesn't have a default value
at com.mysql.jdbc.ServerPreparedStatement.executeBatch(ServerPreparedStatement.java:657)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
... 31 more
Name and version of the database you are using:
MySQL 5.0 Community Edition
The generated SQL (show_sql=true):
insert into wsx_hib.wsx_group (lang_id, group_name, lang_fixed, group_system, group_id, org_id) values (?, ?, ?, ?, ?, ?)
Debug level Hibernate log excerpt:
|