-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: composite key with generated value / insertable ignored
PostPosted: Fri Jun 22, 2012 7:21 am 
Newbie

Joined: Tue Aug 16, 2011 8:38 am
Posts: 3
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.