Hallo. I am trying to mark identity value in composite key as insertable = "false", but this value is still in insert SQL.
@Column(name = "jed_data_id", nullable = true, insertable = false) private Integer jednotkaDataId;
generates this sql insert
insert into ... (.., jed_data_id) values (?,...,?),
and next thing; Hibernate manual 3.6.5.Final contains this fragment:
<class name="Customer"> <composite-id name="id" class="CustomerId"> <key-property name="firstName" column="userfirstname_fk"/> <key-property name="lastName" column="userfirstname_fk"/> <key-property name="customerNumber"/> </composite-id> <property name="preferredCustomer"/> <many-to-one name="user"> <column name="userfirstname_fk" updatable="false" insertable="false"/> <column name="userlastname_fk" updatable="false" insertable="false"/> </many-to-one> </class>
but hibernate-mapping-3.0.dtd does not alow attribute "insertable"; how could be this fragment working??
I am working with existing database (using rev. eng.) which uses composite keys including identities (due to some security reasons).
I tried more ways how to resolve this problem - modify Insert (override addColumn by replacing addIdentityColumn for identity column)
AbstractReturningDelegate x = new AbstractReturningDelegate(postinsertidentitypersister) {
@Override public IdentifierGeneratingInsert prepareIdentifierGeneratingInsert() { final IdentifierGeneratingInsert identifierGeneratingInsert = new MyInsert(dialect); return identifierGeneratingInsert; } .... }
but this MyInsert is not used for creating sql insert for values from composite key ; I tried to modify prepared statement and set values from composite keys mannualy, but generator is created once (one instance) and I am not able to transfer some assigned values( from method public Serializable generate(SessionImplementor sessionimplementor, Object value)) to this method:
@Override protected Serializable executeAndExtract(PreparedStatement preparedstatement) throws SQLException { //SQL insert was modified in protected PreparedStatement prepare(String insertSQL, SessionImplementor sessionimplementor) preparedstatement.setInteger(...) preparedstatement.executeUpdate(); return new JednotkaDataId(); }
Do you have any solution for composite keys with generated values (auto, identity, ...)? Thank you. M.P.
|