-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problem with @CollectionTable in 3.5.1
PostPosted: Tue Apr 27, 2010 2:59 pm 
Newbie

Joined: Tue Apr 27, 2010 2:32 pm
Posts: 1
I've encountered a problem that may be a hibernate collection bug. Using the code listed below, I'm creating collection table that has two columns: TERRITORY_ID and characters_CHARACTER_ID. When hibernate creates the table, it creates the following indexes:

1. An compound unique index on TERRITORY_ID and characters_CHARACTER_ID, which is expected.
2. A non-unique on both TERRITORY_ID and characters_CHARACTER_ID, which is expected.
3. A unique index on characters_CHARACTER_ID, which is the problem.

Why is the unique index on characters_CHARACTER_ID being created? If I manually drop the index, my code works fine. Otherwise, I get a unique constraint violation when I try to insert more than one of the same character id into the table. Not the desired behavior. I'd rather not put SQL in my code to delete the index. Has anyone else encountered this problem?

Code:

public class Territory implements Serializable {
    private static final long serialVersionUID = -8906914598601073008L;

    @Id
    @Column(name = "TERRITORY_ID", length = 50)
    private String territoryId;

    @ElementCollection(fetch = FetchType.LAZY)
    @CollectionTable(name="TERRITORY_CHARACTER", joinColumns=@JoinColumn(name="TERRITORY_ID"))
    @Column(name="CHARACTER_ID")
    private Set<Character> characters;

    ...
}

public class Character implements Serializable {
    private static final long serialVersionUID = 845127746329423630L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "CHARACTER_ID")
    private Long characterId;
    ...
}



Top
 Profile  
 
 Post subject: Re: Problem with @CollectionTable in 3.5.1
PostPosted: Tue May 04, 2010 7:03 pm 
Newbie

Joined: Tue May 04, 2010 6:54 pm
Posts: 1
I have same problem

Code:
@Entity(name = "test")
@Table(name = "test")
public class Test {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column
    private int id;
    @ElementCollection(fetch = FetchType.LAZY, targetClass=User.class)
    @CollectionTable(name = "test_users", joinColumns = @JoinColumn(name = "test_id"))
    private Collection<User> users;
}


@Entity(name = "user")
@Table(name = "user")
public class User {
...
}



Hibernate create unique users_id, and I get a unique constraint violation when I try to insert more than one of the same user.


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

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.