Hibernate version: 2.1.6
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>
<!--
Created by the Middlegen Hibernate plugin 2.1
http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->
<class name="sumex_tms.server.persistence.mapping.TariffNode"
table="TARIFFNODE" schema="TMS">
<id name="tariffNodeId" column="TARIFFNODE_ID" type="java.lang.Long">
<generator class="sequence">
<param name="sequence">S_TARIFFNODE</param>
</generator>
</id>
<property name="logicalKey" type="java.math.BigDecimal"
column="LOGICALKEY" length="38" not-null="true"/>
<property name="knownFrom" type="java.sql.Timestamp"
column="KNOWN_FROM" length="7" not-null="true"/>
<property name="knownTo" type="java.sql.Timestamp" column="KNOWN_TO" length="7"/>
<property name="validFrom" type="java.sql.Timestamp"
column="VALID_FROM" length="7" not-null="true"/>
<property name="validTo" type="java.sql.Timestamp" column="VALID_TO" length="7"/>
<property name="validityCode" type="java.lang.String"
column="VALIDITYCODE" length="1"/>
<!-- Associations
bi-directional many-to-one association to OperandType -->
<many-to-one name="operandType"
class="sumex_tms.server.persistence.mapping.OperandType" not-null="true">
<column name="OPERANDTYPE_ID"/>
</many-to-one>
<!-- bi-directional one-to-many association to TariffNodeLink -->
<set name="tariffNodeLinksByChildId" lazy="true" cascade="save-update">
<key>
<column name="CHILD_ID"/>
</key>
<one-to-many class="sumex_tms.server.persistence.mapping.TariffNodeLink"/>
</set>
<!-- bi-directional one-to-many association to TariffNodeLink -->
<set name="tariffNodeLinksByParentId" lazy="true" cascade="save-update">
<key>
<column name="PARENT_ID"/>
</key>
<one-to-many class="sumex_tms.server.persistence.mapping.TariffNodeLink"/>
</set>
<!-- uni-directional one-to-many association to NodeDatatypeList -->
<set name="nodeDatatypeLists" lazy="true">
<key>
<column name="NODE_ID"/>
</key>
<one-to-many class="sumex_tms.server.persistence.mapping.NodeDatatypeList"/>
</set>
<!-- bi-directional one-to-many association to Taxpoint -->
<set name="taxpoints" lazy="true" inverse="true">
<key>
<column name="TARIFFNODE_ID"/>
</key>
<one-to-many class="sumex_tms.server.persistence.mapping.Taxpoint"/>
</set>
<!-- bi-directional one-to-many association to SuperRule -->
<set name="superRules" lazy="true" inverse="true">
<key>
<column name="TARIFFNODE_ID"/>
</key>
<one-to-many class="sumex_tms.server.persistence.mapping.SuperRule"/>
</set>
<!-- bi-directional one-to-many association to Price -->
<set name="prices" lazy="true" inverse="true">
<key>
<column name="TARIFFNODE_ID"/>
</key>
<one-to-many class="sumex_tms.server.persistence.mapping.Price"/>
</set>
<!-- bi-directional one-to-many association to Factor -->
<set name="factors" lazy="true" inverse="true">
<key>
<column name="TARIFFNODE_ID"/>
</key>
<one-to-many class="sumex_tms.server.persistence.mapping.Factor"/>
</set>
<!-- bi-directional one-to-many association to RuleTariffNodeList -->
<set name="ruleTariffNodeLists" lazy="true" inverse="true">
<key>
<column name="TARIFFNODE_ID"/>
</key>
<one-to-many class="sumex_tms.server.persistence.mapping.RuleTariffNodeList"/>
</set>
<!-- uni-directional one-to-many association to Description -->
<set name="descriptions" lazy="true">
<key>
<column name="FOREIGNNODE_ID"/>
</key>
<one-to-many class="sumex_tms.server.persistence.mapping.Description"/>
</set>
<!-- bi-directional one-to-many association to TariffInfo -->
<set name="tariffInfos" lazy="true" inverse="true">
<key>
<column name="TARIFFNODE_ID"/>
</key>
<one-to-many class="sumex_tms.server.persistence.mapping.TariffInfo"/>
</set>
<!-- bi-directional one-to-many association to Galdat -->
<set name="galdats" lazy="true" inverse="true">
<key>
<column name="TARIFFNODE_ID"/>
</key>
<one-to-many class="sumex_tms.server.persistence.mapping.Galdat"/>
</set>
<!-- bi-directional one-to-many association to RoleTariffNodePermList -->
<set name="roleTariffNodePermLists" lazy="true" inverse="true">
<key>
<column name="TARIFFNODE_ID"/>
</key>
<one-to-many class="sumex_tms.server.persistence.mapping.RoleTariffNodePermList"/>
</set>
<!-- bi-directional many-to-one association to Mutation -->
<many-to-one name="mutation"
class="sumex_tms.server.persistence.mapping.Mutation" not-null="true">
<column name="MUTATION_ID"/>
</many-to-one>
<!-- bi-directional many-to-many association to NodeDatatype -->
<set name="nodeDatatypes" table="NODEDATATYPELIST" lazy="true">
<key>
<column name="NODE_ID"/>
</key>
<many-to-many class="sumex_tms.server.persistence.mapping.NodeDatatype">
<column name="NODEDATATYPE_ID"/>
</many-to-many>
</set>
<!-- bi-directional many-to-many association to Rule -->
<set name="rules" table="RULETARIFFNODELIST" lazy="true">
<key>
<column name="TARIFFNODE_ID"/>
</key>
<many-to-many class="sumex_tms.server.persistence.mapping.Rule">
<column name="RULE_ID"/>
</many-to-many>
</set>
<!-- bi-directional many-to-many association to Role -->
<set name="roles" table="ROLETARIFFNODEPERMLIST" lazy="true">
<key>
<column name="TARIFFNODE_ID"/>
</key>
<many-to-many class="sumex_tms.server.persistence.mapping.Role">
<column name="ROLE_ID"/>
</many-to-many>
</set>
<!-- bi-directional many-to-many association to TariffNode -->
<set name="children" table="TARIFFNODELINK" lazy="true" cascade="save-update">
<key>
<column name="CHILD_ID"/>
</key>
<many-to-many class="sumex_tms.server.persistence.mapping.TariffNode">
<column name="PARENT_ID"/>
</many-to-many>
</set>
<!-- bi-directional many-to-many association to TariffNode -->
<set name="parents" table="TARIFFNODELINK" lazy="true" cascade="save-update">
<key>
<column name="PARENT_ID"/>
</key>
<many-to-many class="sumex_tms.server.persistence.mapping.TariffNode">
<column name="CHILD_ID"/>
</many-to-many>
</set>
</class>
</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>
<!--
Created by the Middlegen Hibernate plugin 2.1
http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->
<class name="sumex_tms.server.persistence.mapping.TariffNodeLink"
table="TARIFFNODELINK" schema="TMS">
<id name="tariffNodeLinkId" column="TARIFFNODELINK_ID" type="java.lang.Long">
<generator class="native"/>
</id>
<property name="logicalKey" type="java.math.BigDecimal"
column="LOGICALKEY" length="38" not-null="true"/>
<property name="knownFrom" type="java.sql.Timestamp"
column="KNOWN_FROM" length="7" not-null="true"/>
<property name="knownTo" type="java.sql.Timestamp" column="KNOWN_TO" length="7"/>
<property name="validFrom" type="java.sql.Timestamp"
column="VALID_FROM" length="7" not-null="true"/>
<property name="validTo" type="java.sql.Timestamp" column="VALID_TO" length="7"/>
<property name="validityCode" type="java.lang.String"
column="VALIDITYCODE" length="1"/>
<property name="linkType" type="java.lang.String" column="LINKTYPE"
length="1" not-null="true"/>
<!-- Associations
uni-directional one-to-many association to Description -->
<set name="descriptions" lazy="true">
<key>
<column name="FOREIGNNODE_ID"/>
</key>
<one-to-many class="sumex_tms.server.persistence.mapping.Description"/>
</set>
<!-- bi-directional many-to-one association to TariffNode -->
<many-to-one name="tariffNodeByChildId"
class="sumex_tms.server.persistence.mapping.TariffNode"
not-null="true" cascade="save-update">
<column name="CHILD_ID"/>
</many-to-one>
<!-- bi-directional many-to-one association to TariffNode -->
<many-to-one name="tariffNodeByParentId"
class="sumex_tms.server.persistence.mapping.TariffNode"
not-null="true" cascade="save-update">
<column name="PARENT_ID"/>
</many-to-one>
<!-- bi-directional many-to-one association to Mutation -->
<many-to-one name="mutation"
class="sumex_tms.server.persistence.mapping.Mutation" not-null="true">
<column name="MUTATION_ID"/>
</many-to-one>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
cfg.Environment 469 ) Hibernate 2.1.6
(cfg.Environment 498 ) hibernate.properties not found
(cfg.Environment 529 ) using CGLIB reflection optimizer
(cfg.Configuration 895 ) configuring from resource: /hibernate.cfg.xml
(cfg.Configuration 867 ) Configuration resource: /hibernate.cfg.xml
.... mapping classes initialisation
(cfg.Configuration 636 ) processing one-to-one association property references
(cfg.Configuration 661 ) processing foreign key constraints
(dialect.Dialect 82 ) Using dialect: net.sf.hibernate.dialect.Oracle9Dialect
(cfg.SettingsFactory 63 ) Use outer join fetching: true
(connection.DriverManagerConnectionProvider 42 ) Using Hibernate built-in connection pool (not for production use!)
(connection.DriverManagerConnectionProvider 43 ) Hibernate connection pool size: 20
(connection.DriverManagerConnectionProvider 77 ) using driver: oracle.jdbc.driver.OracleDriver at URL: jdbc:oracle:thin:@pcfse:1521:ora9ifse
(connection.DriverManagerConnectionProvider 78 ) connection properties: {user=TMS, password=PASSWORD}
(transaction.TransactionManagerLookupFactory 33 ) No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
(cfg.SettingsFactory 103 ) Use scrollable result sets: true
(cfg.SettingsFactory 106 ) Use JDBC3 getGeneratedKeys(): false
(cfg.SettingsFactory 109 ) Optimize cache for minimal puts: false
(cfg.SettingsFactory 112 ) Default schema set to: TMS
(cfg.SettingsFactory 115 ) echoing all SQL to stdout
(cfg.SettingsFactory 118 ) Query language substitutions: {}
(cfg.SettingsFactory 129 ) cache provider: net.sf.hibernate.cache.EhCacheProvider
(cfg.Configuration 1116) instantiating and configuring caches
(impl.SessionFactoryImpl 118 ) building session factory
(impl.SessionFactoryObjectFactory 82 ) Not binding factory to JNDI, no JNDI name configured
(util.JDBCExceptionReporter 38 ) SQL Error: 1400, SQLState: 23000
(util.JDBCExceptionReporter 46 ) ORA-01400: cannot insert NULL in ("TMS"."TARIFFNODELINK"."TARIFFNODELINK_ID")
Name and version of the database you are using: Oracle 9i
The generated SQL (show_sql=true):
...
Hibernate: select S_TARIFFNODE.nextval from dual
...
Hibernate: insert into TMS.TARIFFNODE (LOGICALKEY, KNOWN_FROM, KNOWN_TO, VALID_FROM, VALID_TO, VALIDITYCODE, OPERANDTYPE_ID, MUTATION_ID, TARIFFNODE_ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into TMS.TARIFFNODELINK (CHILD_ID, PARENT_ID) values (?, ?)
-------
Hi
I have a data model where a graph structure for elements (table TARIFFNODE) is designed as a many to many relationship with a link table (TARIFFNODELINK) see above for the mapping files.
The link columns are PARENT_ID and CHILD_ID in the link table which refer to TARIFFNODE_ID in the element table. Additionally the link table as a primary key TARIFFNODELINK_ID.
The problem is the following: when I create a child element, link it to the parent element and save it, Hibernate performs the insert in the link table (see trace above) using the parent_id and child_id columns, but there is no sequence generated for the primary key of the link table.
I tried many types of generators (sequence, incremental, native). I get always the same error. I don't know how to 'tell' hibernate to generate the primary key of the link table.
Thanks in advance for help
Fab