@BasicCollection not updating on merge

View: New views
3 Messages — Rating Filter:   Alert me  

@BasicCollection not updating on merge

by Stephiems :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I haven't really used a BasicCollection before, so it is possible I'm not using it correctly.

Basically I've set-up a User-Role relationship, and I've used a BasicCollection for the roles. I've got it working so that on persist, the roles are also persisted and so when I get that same object again, I have the roles that were originally persisted. My trouble is now on merge. When I change the Set that holds the roles, and then merge or commit, the database does not update. I know I am mergine the object correctly because if I change a different value that is updating in the database, it is only the roles that don't seem to be cascading.

From my User class:

@ObjectTypeConverter (
    name = "roleEnumFromStringConversion",
    objectType = Role.class,
    dataType = String.class,
    conversionValues = {
        @ConversionValue(objectValue = "ADMIN_ROLE", dataValue = "ADMIN"),
        @ConversionValue(objectValue = "USER_ROLE", dataValue = "USER")
    }
)

AND

@BasicCollection(
        fetch = FetchType.EAGER,
        valueColumn = @Column(name = "ROLE")
    )
    @CollectionTable(
        name = "USER_ROLE",
        primaryKeyJoinColumns = {
            @PrimaryKeyJoinColumn(name = "USER_ID", referencedColumnName = "USER_ID")
        }
    )
    @Convert("roleEnumFromStringConversion")
    private Set<Role> roles;

Thanks ahead of time for your help,
Stephanie

Re: @BasicCollection not updating on merge

by James Sutherland :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Your mapping looks correct.  Could you include the code you use to read/update/merge the object, and the version of EclipseLink you are using.

If you make the relationship lazy, or use a List instead of Set, or update the managed object instead of merging, does it work?


Stephiems wrote:
I haven't really used a BasicCollection before, so it is possible I'm not using it correctly.

Basically I've set-up a User-Role relationship, and I've used a BasicCollection for the roles. I've got it working so that on persist, the roles are also persisted and so when I get that same object again, I have the roles that were originally persisted. My trouble is now on merge. When I change the Set that holds the roles, and then merge or commit, the database does not update. I know I am mergine the object correctly because if I change a different value that is updating in the database, it is only the roles that don't seem to be cascading.

From my User class:

@ObjectTypeConverter (
    name = "roleEnumFromStringConversion",
    objectType = Role.class,
    dataType = String.class,
    conversionValues = {
        @ConversionValue(objectValue = "ADMIN_ROLE", dataValue = "ADMIN"),
        @ConversionValue(objectValue = "USER_ROLE", dataValue = "USER")
    }
)

AND

@BasicCollection(
        fetch = FetchType.EAGER,
        valueColumn = @Column(name = "ROLE")
    )
    @CollectionTable(
        name = "USER_ROLE",
        primaryKeyJoinColumns = {
            @PrimaryKeyJoinColumn(name = "USER_ID", referencedColumnName = "USER_ID")
        }
    )
    @Convert("roleEnumFromStringConversion")
    private Set<Role> roles;

Thanks ahead of time for your help,
Stephanie

Re: @BasicCollection not updating on merge

by Stephiems :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks so much for your help.

While going through the steps to try all the stuff you said, I discovered that I wasn't removing the roles from the Set. When I switched it to a List, it was inserting multiple copies because I wasn't clearing the original ones before adding the new ones.

It is all working well now, sorry for the trouble.

Cheers,
Stephanie


Your mapping looks correct.  Could you include the code you use to read/update/merge the object, and the version of EclipseLink you are using.

If you make the relationship lazy, or use a List instead of Set, or update the managed object instead of merging, does it work?


Stephiems wrote:
I haven't really used a BasicCollection before, so it is possible I'm not using it correctly.

Basically I've set-up a User-Role relationship, and I've used a BasicCollection for the roles. I've got it working so that on persist, the roles are also persisted and so when I get that same object again, I have the roles that were originally persisted. My trouble is now on merge. When I change the Set that holds the roles, and then merge or commit, the database does not update. I know I am mergine the object correctly because if I change a different value that is updating in the database, it is only the roles that don't seem to be cascading.

From my User class:

@ObjectTypeConverter (
    name = "roleEnumFromStringConversion",
    objectType = Role.class,
    dataType = String.class,
    conversionValues = {
        @ConversionValue(objectValue = "ADMIN_ROLE", dataValue = "ADMIN"),
        @ConversionValue(objectValue = "USER_ROLE", dataValue = "USER")
    }
)

AND

@BasicCollection(
        fetch = FetchType.EAGER,
        valueColumn = @Column(name = "ROLE")
    )
    @CollectionTable(
        name = "USER_ROLE",
        primaryKeyJoinColumns = {
            @PrimaryKeyJoinColumn(name = "USER_ID", referencedColumnName = "USER_ID")
        }
    )
    @Convert("roleEnumFromStringConversion")
    private Set<Role> roles;

Thanks ahead of time for your help,
Stephanie