4 Replies Latest reply on Oct 2, 2006 3:03 PM by bluetrade

    ConstraintViolation & redundant entries

    bluetrade

      Hi,
      i have a problem with persisting entities and get ConstraintViolationExceptions . In Hibernate, there is a saveOrUpdate feature that is missing in the EJB 3.0 Persistence specification, as far as I know merge is not the same (and that didn't work for me anyways). I have a Text-Object that contains Sentence Objects which in turn contain words. Now I don't want to have double entries of certain words but rather e.g. persisting "This car is his car" should not add two times "car" into the DB. To avoid that, I tried using the actual token (String token of Word Object) as the PK but that results in ConstraintViolationExceptions...

      Any clues?


      Thanks,
      Joey

        • 1. Re: ConstraintViolation & redundant entries
          bluetrade

          So I tried the same without the hirarchy by just persisting the same word multiple times (via merge) and that worked. So it's not the PK. So I conclude there is something wrong with the Cascading settings. I use Hibernate Entity Manager 3.2.0CR1 along with Annotations 3.2.0 CR1.
          Any clues on this?
          THanks,
          Joey

          • 2. Re: ConstraintViolation & redundant entries
            bluetrade

            mhm... the EntityManager really seems to propagate the "merge"-operation as a "persist"-operation down...
            is this a bug?

            • 3. Re: ConstraintViolation & redundant entries
              bluetrade

              Hi,
              so i found the problem but no solution. The problem is that the foreign key of the referenced "Word" is inside the Join-Table marked as unique, which I switched manually to index.
              Anyone got any clues on how I can avoid the word_content being unique in the join table? Thanks!!

              @OneToMany
               @JoinTable(name="sentence_word",
               joinColumns={@JoinColumn(name="sentence_id")},
               inverseJoinColumns={@JoinColumn(name="word_content",referencedColumnName="content")})
              
               /**
               * @return the words
               */
               public Collection<Word> getWords() {
               return words;
               }
              


              • 4. Re: ConstraintViolation & redundant entries
                bluetrade

                After some experimenting I found that I really should have a ManyToMany relationship :)
                Thanks anyways...
                Joey