-->
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: Managing Sequence column of a table with Unique constraint
PostPosted: Tue Jan 20, 2009 7:22 pm 
Newbie

Joined: Tue Jan 20, 2009 6:11 pm
Posts: 1
Using Hibernate : 3.3.3

I think hibernate can do this, I have just not been able to figure out how.

I have two Tables

Parent.java
Code:
public class Parent implements Serializable {

    private Long id;
    private List<Child> children;

}




Child.java
Code:
public class Child implements Serializable {

    private Long id;
    private Long parent_id;
    private Integer sequenceNumber;

}


There is a unique constraint on (parent_id, sequenceNumber)



sequenceNumber is managed by Hibernate based on Child's position in the list located in Parent DTO.

Through the front end, user can add multiple Child DTOs to the Parent DTO as well as resequence them on the same screen.

Here goes the problem....

Parent has Child records with sequenceNumber 1 and 2. User adds a new Child record to the list at position 2. On commit the newly added Child record gets position 2 and old Child record at position 2 should now be to position 3. All this happens in the one Transaction. This causes unique constraint violation and blows up.

How to solve this without removing unique constraint as well as splitting the operations in to two different Transactions.

Thanks for your Help.


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.