It's not a secret anymore!*
The moose likes Object Relational Mapping and the fly likes concurrent insertion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "concurrent insertion" Watch "concurrent insertion" New topic
Author

concurrent insertion

tej ku
Greenhorn

Joined: Mar 13, 2010
Posts: 19
Hi I have scenario where

operation 1: 2 user read data from table1 and table2

table3 is a link table for table1 and table2 which has foreign keys of table1 and table2.

operation2: the first user has inserted a new record in table3
operation3: later the second user is also inserting a new record in table3 which is not aware already a record is inserted

I am using hibernate mapping but we are not using hibernate version check ....................

How to prevent multiple record in table3?

in mapping files or for every insertion I have to check already a record in table3?

How should be the mappings file declared?

I just changed the names of mapping ..........
<hibernate-mapping>
<class name=" " table="table3_LINK">
<meta attribute="extends" inherit="false">BaseModel</meta>
<meta attribute="class-code" inherit="false">private static final long serialVersionUID = 1L;</meta>
<id name="id" type="java.lang.Long">
<column name="table3_ID" precision="15" scale="0" />
<generator class="identity"></generator>
</id>
<many-to-one name="Employer" class=".model.businessobject.table1" fetch="select">
<column name="FK_table1_ID" precision="15" scale="0" not-null="true" />
</many-to-one>
<many-to-one name="rc" class=".model.businessobject.table2" fetch="select">
<column name="FK_table2_ID" precision="15" scale="0" not-null="true" />
</many-to-one>
<property name="intPartyInd" type=".model.hibernateext.TrimmedString">
<column name="column3_table3" length="1" not-null="true" />
</property>
<property name="mailto1Ind" type=".model.hibernateext.TrimmedString">
<column name="Column4_table4" length="1" not-null="true">
</column>
</property>









Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Would you not just use a unique index on your link table?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
tej ku
Greenhorn

Joined: Mar 13, 2010
Posts: 19
I want to make combination of two Foreign keys in table3 unique.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

OK. So would you not just use a unique index on your link table?
tej ku
Greenhorn

Joined: Mar 13, 2010
Posts: 19
Can you give me a example of how hibernate mappling file should look like.........
tej ku
Greenhorn

Joined: Mar 13, 2010
Posts: 19
I guess we can make multiple column unique by two ways "composite-id" and "unique-key".......What is the difference between using "composite-id" and "unique-key" constraint?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: concurrent insertion
 
Similar Threads
Common DAO layer Code Base - Hibernate Mapping XML changes
problem with hibernate
Hibernate Spring problem with Illegal attempt to associate a collection with two open sessions
Many to Many mapping in hibernate.
Inner Object Loading issue