-->
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: Envers primary key for @ElementCollection map
PostPosted: Mon Jan 27, 2014 3:16 pm 
Newbie

Joined: Tue Sep 01, 2009 5:33 pm
Posts: 3
I have an entity class with an @ElementCollection Map<String, String> property.

Due to application requirements, the map value must support unlimited length strings. I have annotated the entity class accordingly so that the resulting table, in MySQL, has a value column of type longtext.

When I try to add Envers auditing to my class (using Hibernate version 4.2.8), the default DDL generated to create the audit table (xxx_aud) tries to define a primary key that includes both the map key and the map value. MySQL does not allow a longtext column to be included in a primary key, so the DDL fails.

It appears that the reason Envers wants to include the map value in the key has to do with how map value changes are handled. In this case Envers generates two audit rows, one for removing the old value and one for adding the new value. These two rows have the same rev ID and the same map key, but different values for the map value, AND different values for the revision type (revtype).

So, as a workaround, I manually created the audit table using the revision type (revtype) column instead of the map value as part of the primary key. So far, at least, this seems to work.

Does anyone see any problems with this workaround? And if not, wouldn't it be a better approach for Envers to use by default? Given that the revtype is always the same datatype (int) but the map value datatype may vary by application, it would seem to make more sense. Or am I missing some possible situation where two audit rows might be inserted with the same rev, revtype, entity key, and map key?

Thanks,

Jon


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.