Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Dynamic updateble attribute (set field to updatable=false in certain conditions)
Dynamic updateble attribute [message #649486] Wed, 19 January 2011 12:54 Go to next message
Radu  is currently offline Radu Friend
Messages: 12
Registered: August 2010
Junior Member
Hi all,

I'm trying to define field level security using eclipselink in JPA 2 environment (Glassfish 3.1 b37, eclipselink 2.2.0-M6).

I'm using the following code to get field definition.

JpaEntityManager elEm = (JpaEntityManager) em.getDelegate();
ClassDescriptor entityDescriptor = elEm.getActiveSession().getDescriptor(entityObject);
DatabaseField fieldDefinition = entityDescriptor.getMappingForAttributeName("testUpdatedField ").getField();
boolean fieldIsUpdatable = fieldDefinition.isUpdatable();

How can the field be excluded from the SQL UPDATE?

fieldDefinition.setUpdatable(false);

doesn't work.

Thanks!
Re: Dynamic updateble attribute [message #649525 is a reply to message #649486] Wed, 19 January 2011 15:02 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
Hello,

Is there a reason it cannot be done upfront, before login?

The DatabaseField objects you are trying to manipulate are mostly used for DDL generation and to indiecate what settings to use when the mappings are created. They will not change the mappings after they are initialized, and so cannot be used to change field dynamically.

You will need to make these changes code in a customizer or pre-login event for them to affect the mappings.

Best Regards,
Chris
Re: Dynamic updateble attribute [message #649534 is a reply to message #649525] Wed, 19 January 2011 15:37 Go to previous messageGo to next message
Radu  is currently offline Radu Friend
Messages: 12
Registered: August 2010
Junior Member
Thanks for reply Chris,

I only try to modify the "updatable" attribute from @Column annotation:

@Column(name = "CREATED_BY", length = 100, updatable = false) private String createdBy;

This should only specify whether the column is included in SQL UPDATE statement, no DDL generation is involved.

The reason is that based on the Role, some users might not be allowed to view certain column values. So the values are set to null on postLoad events.

I need to exclude those fields from the UPDATE statement, otherwise the null value will be propagated to database.

The approach with DatabaseField it seams most easy to achieve.
Re: Dynamic updateble attribute [message #649772 is a reply to message #649486] Thu, 20 January 2011 14:56 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

You could try using the aboutToUpdate event to remove the fields from the update row.

I may be best to have two different classes mapped to the table and use one versus the other in the application based on the role. i.e. UnscureEmployee and SecureEmployee. They could share a common @MappedSuperclass for the unsecure data.


James : Wiki : Book : Blog : Twitter
Previous Topic:problem using DynamicJAXBContextFactory with xs:base64Binary
Next Topic:Persisting PGgeomerty with custom SRID
Goto Forum:
  


Current Time: Fri Apr 26 22:53:25 GMT 2024

Powered by FUDForum. Page generated in 0.02659 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top